Bug 12816

Summary: layer without priority causes crash instead of reporting error
Product: [Build System, Metadata & Runtime] BitBake Reporter: David Reyna <david.reyna>
Component: bitbakeAssignee: David Reyna <david.reyna>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: poky.bs.watcher, poky.watcher
Version: unspecified   
Target Milestone: 2.6 M4   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description David Reyna 2018-06-28 00:23:49 UTC
In "cooker.py" there is a section of code that scans a layer for its priority.

However, only the success path avoids an otherwise undefined variable, so the error is not reported and bitbake crashes. This was found while experimenting with a weak layer.
  
  UnboundLocalError: local variable 'cre' referenced before assignment

Here is the code in question. Notice that 'cre' is only defined on the success path.

vvvvvvv
# Calculate all layer priorities using calc_layer_priority and store in bbfile_config_priorities
for c in collection_list:
    calc_layer_priority(c)
    regex = self.data.getVar("BBFILE_PATTERN_%s" % c)
    if regex == None:
        parselog.error("BBFILE_PATTERN_%s not defined" % c)
        errors = True
        continue
    elif regex == "":
        parselog.debug(1, "BBFILE_PATTERN_%s is empty" % c)
        errors = False
    else:
        try:
            cre = re.compile(regex)
        except re.error:
            parselog.error("BBFILE_PATTERN_%s \"%s\" is not a valid regular expression", c, regex)
            errors = True
            continue
    self.bbfile_config_priorities.append((c, regex, cre, collection_priorities[c]))
^^^^^^^^

I propose that the resolution is to move the append right after 'cre' is defined, since that is the only success path.
Comment 1 David Reyna 2018-10-01 21:45:57 UTC
This was fixed by this commit:

  commit fe70fd1a03dcbf516ee10866b8a68daf942c0a07
  Author: Robert Yang <liezhi.yang@windriver.com>
  Date:   Thu Feb 1 23:15:22 2018 +0800

    bitbake: bitbake: cooker: skip when BBFILE_PATTERN is empty