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>
This commit is contained in:
Ed Bartosh 2016-12-21 17:05:11 +02:00 committed by Richard Purdie
parent e30f00bca5
commit 5651e8da60
1 changed files with 6 additions and 8 deletions

View File

@ -27,6 +27,7 @@
"""Miscellaneous functions.""" """Miscellaneous functions."""
import os import os
import re
from collections import defaultdict from collections import defaultdict
from distutils import spawn from distutils import spawn
@ -148,21 +149,18 @@ class BitbakeVars(defaultdict):
self.default_image = None self.default_image = None
self.vars_dir = None self.vars_dir = None
def _parse_line(self, line, image): def _parse_line(self, line, image, matcher=re.compile(r"^(\w+)=(.+)")):
""" """
Parse one line from bitbake -e output or from .env file. Parse one line from bitbake -e output or from .env file.
Put result key-value pair into the storage. Put result key-value pair into the storage.
""" """
if "=" not in line: if "=" not in line:
return return
try: match = matcher.match(line)
key, val = line.split("=") if not match:
except ValueError:
return return
key = key.strip() key, val = match.groups()
val = val.strip() self[image][key] = val.strip('"')
if key.replace('_', '').isalnum():
self[image][key] = val.strip('"')
def get_var(self, var, image=None): def get_var(self, var, image=None):
""" """