diff options
| author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-12-21 17:05:11 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-16 18:05:12 +0000 |
| commit | 5651e8da6089eb638ab938cb21fd95ec327e84b5 (patch) | |
| tree | b12915049702d3a2d5b91676e9d37bc4c66c827c | |
| parent | e30f00bca5f61e9693d59e763a3dce633d76f00b (diff) | |
| download | poky-5651e8da6089eb638ab938cb21fd95ec327e84b5.tar.gz | |
wic: fix parsing of 'bitbake -e' output
Current parsing code can wrongly interpret arbitrary lines
that are of 'key=value' format as legitimate bitbake variables.
Implemented more strict parsing of key=value pairs using
regular expressions.
(From OE-Core rev: f0ec387ad40fb9c098ac8d761993bc2bacc76e65)
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | scripts/lib/wic/utils/oe/misc.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py index fe188c9d26..2a2fcc94fb 100644 --- a/scripts/lib/wic/utils/oe/misc.py +++ b/scripts/lib/wic/utils/oe/misc.py | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | """Miscellaneous functions.""" | 27 | """Miscellaneous functions.""" |
| 28 | 28 | ||
| 29 | import os | 29 | import os |
| 30 | import re | ||
| 30 | from collections import defaultdict | 31 | from collections import defaultdict |
| 31 | from distutils import spawn | 32 | from distutils import spawn |
| 32 | 33 | ||
| @@ -148,21 +149,18 @@ class BitbakeVars(defaultdict): | |||
| 148 | self.default_image = None | 149 | self.default_image = None |
| 149 | self.vars_dir = None | 150 | self.vars_dir = None |
| 150 | 151 | ||
| 151 | def _parse_line(self, line, image): | 152 | def _parse_line(self, line, image, matcher=re.compile(r"^(\w+)=(.+)")): |
| 152 | """ | 153 | """ |
| 153 | Parse one line from bitbake -e output or from .env file. | 154 | Parse one line from bitbake -e output or from .env file. |
| 154 | Put result key-value pair into the storage. | 155 | Put result key-value pair into the storage. |
| 155 | """ | 156 | """ |
| 156 | if "=" not in line: | 157 | if "=" not in line: |
| 157 | return | 158 | return |
| 158 | try: | 159 | match = matcher.match(line) |
| 159 | key, val = line.split("=") | 160 | if not match: |
| 160 | except ValueError: | ||
| 161 | return | 161 | return |
| 162 | key = key.strip() | 162 | key, val = match.groups() |
| 163 | val = val.strip() | 163 | self[image][key] = val.strip('"') |
| 164 | if key.replace('_', '').isalnum(): | ||
| 165 | self[image][key] = val.strip('"') | ||
| 166 | 164 | ||
| 167 | def get_var(self, var, image=None): | 165 | def get_var(self, var, image=None): |
| 168 | """ | 166 | """ |
