All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [wic][PATCH v2] wic: fix parsing of 'bitbake -e' output
Date: Wed, 21 Dec 2016 17:05:11 +0200	[thread overview]
Message-ID: <1482332711-23829-1-git-send-email-ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <CAD4b0_Kh=LmRhtmKdpS48E5VAb66fj7f2PVbqYeirLj-ZrTX=Q@mail.gmail.com>

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.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
---
 scripts/lib/wic/utils/oe/misc.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index fe188c9..2a2fcc9 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -27,6 +27,7 @@
 """Miscellaneous functions."""
 
 import os
+import re
 from collections import defaultdict
 from distutils import spawn
 
@@ -148,21 +149,18 @@ class BitbakeVars(defaultdict):
         self.default_image = 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.
         Put result key-value pair into the storage.
         """
         if "=" not in line:
             return
-        try:
-            key, val = line.split("=")
-        except ValueError:
+        match = matcher.match(line)
+        if not match:
             return
-        key = key.strip()
-        val = val.strip()
-        if key.replace('_', '').isalnum():
-            self[image][key] = val.strip('"')
+        key, val = match.groups()
+        self[image][key] = val.strip('"')
 
     def get_var(self, var, image=None):
         """
-- 
2.1.4



  reply	other threads:[~2016-12-21 15:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21 14:19 [wic][PATCH] wic: fix parsing of 'bitbake -e' output Ed Bartosh
2016-12-21 14:31 ` Maciej Borzęcki
2016-12-21 15:05   ` Ed Bartosh [this message]
2016-12-21 17:16     ` [wic][PATCH v2] " Maciej Borzęcki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482332711-23829-1-git-send-email-ed.bartosh@linux.intel.com \
    --to=ed.bartosh@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.