Bug 12816 - layer without priority causes crash instead of reporting error
Summary: layer without priority causes crash instead of reporting error
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium normal
Target Milestone: 2.6 M4
Assignee: David Reyna
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2018-06-28 00:23 UTC by David Reyna
Modified: 2018-10-01 21:45 UTC (History)
2 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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