waf: fix array access out of bounds exception in the check for flex
authorRalph Boehme <slow@samba.org>
Fri, 29 Mar 2019 17:18:27 +0000 (18:18 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 24 Apr 2019 18:32:14 +0000 (18:32 +0000)
If flex is not installed the following expection is triggered:

Checking for flex
Checking for program 'flex'                                                       : not found
Traceback (most recent call last):
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 158, in waf_entry_point
    run_commands()
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 251, in run_commands
    ctx = run_command(cmd_name)
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 235, in run_command
    ctx.execute()
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Configure.py", line 159, in execute
    super(ConfigurationContext, self).execute()
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 204, in execute
    self.recurse([os.path.dirname(g_module.root_path)])
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 286, in recurse
    user_function(self)
  File "/home/slow/git/samba/scratch/wscript", line 307, in configure
    conf.RECURSE('source3')
  File "./buildtools/wafsamba/samba_utils.py", line 66, in fun
    return f(*k, **kw)
  File "./buildtools/wafsamba/samba_utils.py", line 481, in RECURSE
    return ctx.recurse(relpath)
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 286, in recurse
    user_function(self)
  File "/home/slow/git/samba/scratch/source3/wscript", line 1660, in configure
    flex.configure(conf)
  File "/home/slow/git/samba/scratch/third_party/waf/waflib/Tools/flex.py", line 59, in configure
    if re.search (r"\\msys\\[0-9.]+\\bin\\flex.exe$", conf.env.FLEX[0]):
IndexError: list index out of range

This happens because when the detection of flex fails, an excpetion is
thrown in Configure.py:find_program by calling self.fatal(), but as
Configure.py:find_program() is called from
samba_waf18.py:find_program_samba() which sets the keyword argument
mandatory=False, Configure.py:conf:fun() catches the expection.

As a result in flex.py the call to conf.find_program('flex', var='FLEX')
does not abort and

  if re.search (r"\\msys\\[0-9.]+\\bin\\flex.exe$", conf.env.FLEX[0])

is executed even though conf.env.FLEX is None.

As this is a not a problem of upstream Samba, but triggered by our
samba_waf18.py:find_program_samba(), I don't pursue an upstream
fix. Instead, just use conf.find_program() directly instead of the
wrapper in flex.py.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/wscript

index 97b51bb1a3e410f8a4d9d537abbab25298b96b43..1a34c8ab679187b5b628288b326bfaf9a92a6c27 100644 (file)
@@ -13,7 +13,7 @@ import build.charset
 from wafsamba import samba_utils
 from samba_utils import TO_LIST
 import samba3
-from waflib.Tools import bison, flex
+from waflib.Tools import bison
 
 default_prefix = Options.default_prefix = '/usr/local/samba'
 
@@ -1647,7 +1647,8 @@ main() {
             conf.fatal("Spotlight support requested but bison missing")
         conf.CHECK_COMMAND('%s --version | head -n1' % conf.env['BISON'], msg='Using bison version', define=None, on_target=False)
         Logs.info("Requested Spotlight support, checking for flex")
-        flex.configure(conf)
+        conf.find_program('flex', var='FLEX')
+        conf.env.FLEXFLAGS = ['-t']
         if not conf.env['FLEX']:
             conf.fatal("Spotlight support requested but flex missing")
         conf.CHECK_COMMAND('%s --version' % conf.env['FLEX'], msg='Using flex version', define=None, on_target=False)