Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 1/1] qemurunner: Sanitize output from qemu and qemu pid
       [not found] <cover.1443162720.git.mariano.lopez@linux.intel.com>
@ 2015-09-25  6:33 ` mariano.lopez
  2015-09-28 14:42   ` Burton, Ross
  0 siblings, 1 reply; 3+ messages in thread
From: mariano.lopez @ 2015-09-25  6:33 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

Currently the output from qemu could contain control
or Unicode characters; having such characters in the
log will cause an internal server error when sending
the report to error reporting web. Control characters
can be found in the command line used to run quemu too.

This change sanitize the output from qemu and the
command line used to run qemu, this way the logs doesn't
contain control or Unicode characters and this will solve
the issue of error reporting web and generate better
logs.

[YOCTO #8225]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
 meta/lib/oeqa/utils/qemurunner.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 0357f99..845a57b 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -13,6 +13,7 @@ import re
 import socket
 import select
 import errno
+import string
 import threading
 from oeqa.utils.dump import HostDumper
 
@@ -61,6 +62,9 @@ class QemuRunner:
 
     def log(self, msg):
         if self.logfile:
+            # It is needed to sanitize the data received from qemu
+            # because is possible to have control characters or Unicode
+            msg = cmdline = "".join(filter(lambda x:x in string.printable, msg))
             with open(self.logfile, "a") as f:
                 f.write("%s" % msg)
 
@@ -170,6 +174,9 @@ class QemuRunner:
             cmdline = ''
             with open('/proc/%s/cmdline' % self.qemupid) as p:
                 cmdline = p.read()
+                # It is needed to sanitize the data received
+                # because is possible to have control characters
+                cmdline = "".join(filter(lambda x:x in string.printable, cmdline))
             try:
                 ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
                 if not ips or len(ips) != 3:
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] qemurunner: Sanitize output from qemu and qemu pid
  2015-09-25  6:33 ` [PATCH 1/1] qemurunner: Sanitize output from qemu and qemu pid mariano.lopez
@ 2015-09-28 14:42   ` Burton, Ross
  2015-09-28 20:02     ` Mariano Lopez
  0 siblings, 1 reply; 3+ messages in thread
From: Burton, Ross @ 2015-09-28 14:42 UTC (permalink / raw)
  To: mariano.lopez; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

On 25 September 2015 at 07:33, <mariano.lopez@linux.intel.com> wrote:

>      def log(self, msg):
>          if self.logfile:
> +            # It is needed to sanitize the data received from qemu
> +            # because is possible to have control characters or Unicode
> +            msg = cmdline = "".join(filter(lambda x:x in
> string.printable, msg))
>              with open(self.logfile, "a") as f:
>                  f.write("%s" % msg)
>

cmdline looks like a copy/paste typo?

Would it be sensible in the future to support UTF-8 for the logging?

Ross

[-- Attachment #2: Type: text/html, Size: 1132 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] qemurunner: Sanitize output from qemu and qemu pid
  2015-09-28 14:42   ` Burton, Ross
@ 2015-09-28 20:02     ` Mariano Lopez
  0 siblings, 0 replies; 3+ messages in thread
From: Mariano Lopez @ 2015-09-28 20:02 UTC (permalink / raw)
  To: Burton, Ross; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]



On 09/28/2015 09:42 AM, Burton, Ross wrote:
> On 25 September 2015 at 07:33, <mariano.lopez@linux.intel.com 
> <mailto:mariano.lopez@linux.intel.com>> wrote:
>
>      def log(self, msg):
>              if self.logfile:
>     +            # It is needed to sanitize the data received from qemu
>     +            # because is possible to have control characters or
>     Unicode
>     +            msg = cmdline = "".join(filter(lambda x:x in
>     string.printable, msg))
>                  with open(self.logfile, "a") as f:
>                      f.write("%s" % msg)
>
>
> cmdline looks like a copy/paste typo?

Yes it is a copy/paste typo, I'll send a v2

>
> Would it be sensible in the future to support UTF-8 for the logging?

Yes, it would be possible to use UTF-8, but the main reason to use 
printable is not Unicode characters, it is the NULL character that 
sometimes appear in the qemu output and always appear in the command 
used to run qemu. Actually, the only non ASCII character that appears is 
the copyright symbol.

>
> Ross

-- 
Mariano Lopez

[-- Attachment #2: Type: text/html, Size: 2806 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-28 20:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1443162720.git.mariano.lopez@linux.intel.com>
2015-09-25  6:33 ` [PATCH 1/1] qemurunner: Sanitize output from qemu and qemu pid mariano.lopez
2015-09-28 14:42   ` Burton, Ross
2015-09-28 20:02     ` Mariano Lopez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox