All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings
@ 2017-03-30 14:44 George McCollister
  2017-03-30 14:44 ` [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string George McCollister
  2017-04-01  4:23 ` [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings Simon Glass
  0 siblings, 2 replies; 6+ messages in thread
From: George McCollister @ 2017-03-30 14:44 UTC (permalink / raw)
  To: u-boot

os.read() returns a byte array in Python 3.5.2 and needs to be converted
into a string. Check if the returned value is an instance of bytes and
if it is decode it as a utf-8 string. If it is not a utf-8 encoded string
the decoding may fail with an exception.

Prior to this fix the comparisions check data == "" would fail when data
was b'' and would cause an infinite memory leaking loop. joins would
also fail with an exception below but due to the infinite loop it never
made it that far.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 tools/patman/cros_subprocess.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/patman/cros_subprocess.py b/tools/patman/cros_subprocess.py
index ebd4300dfd..7c76014340 100644
--- a/tools/patman/cros_subprocess.py
+++ b/tools/patman/cros_subprocess.py
@@ -190,6 +190,8 @@ class Popen(subprocess.Popen):
                 # We will get an error on read if the pty is closed
                 try:
                     data = os.read(self.stdout.fileno(), 1024)
+                    if isinstance(data, bytes):
+                        data = data.decode('utf-8')
                 except OSError:
                     pass
                 if data == "":
@@ -205,6 +207,8 @@ class Popen(subprocess.Popen):
                 # We will get an error on read if the pty is closed
                 try:
                     data = os.read(self.stderr.fileno(), 1024)
+                    if isinstance(data, bytes):
+                        data = data.decode('utf-8')
                 except OSError:
                     pass
                 if data == "":
-- 
2.11.0

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

* [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string
  2017-03-30 14:44 [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings George McCollister
@ 2017-03-30 14:44 ` George McCollister
  2017-04-01  4:23   ` Simon Glass
  2017-04-01  4:23 ` [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings Simon Glass
  1 sibling, 1 reply; 6+ messages in thread
From: George McCollister @ 2017-03-30 14:44 UTC (permalink / raw)
  To: u-boot

With Python 3.5.2 encode will throw an exception if val is a byte array.
Decode it to a string first. This assumes it's utf-8, if it's not valid
utf-8 it will throw an exception.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 tools/dtoc/fdt_util.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index e6d523b9de..b9dfae8d0e 100644
--- a/tools/dtoc/fdt_util.py
+++ b/tools/dtoc/fdt_util.py
@@ -24,6 +24,8 @@ def fdt32_to_cpu(val):
         A native-endian integer value
     """
     if sys.version_info > (3, 0):
+        if isinstance(val, bytes):
+            val = val.decode('utf-8')
         val = val.encode('raw_unicode_escape')
     return struct.unpack('>I', val)[0]
 
-- 
2.11.0

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

* [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings
  2017-03-30 14:44 [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings George McCollister
  2017-03-30 14:44 ` [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string George McCollister
@ 2017-04-01  4:23 ` Simon Glass
  2017-04-13 21:16   ` Simon Glass
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Glass @ 2017-04-01  4:23 UTC (permalink / raw)
  To: u-boot

On 30 March 2017 at 08:44, George McCollister
<george.mccollister@gmail.com> wrote:
> os.read() returns a byte array in Python 3.5.2 and needs to be converted
> into a string. Check if the returned value is an instance of bytes and
> if it is decode it as a utf-8 string. If it is not a utf-8 encoded string
> the decoding may fail with an exception.
>
> Prior to this fix the comparisions check data == "" would fail when data
> was b'' and would cause an infinite memory leaking loop. joins would
> also fail with an exception below but due to the infinite loop it never
> made it that far.
>
> Signed-off-by: George McCollister <george.mccollister@gmail.com>
> ---
>  tools/patman/cros_subprocess.py | 4 ++++
>  1 file changed, 4 insertions(+)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string
  2017-03-30 14:44 ` [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string George McCollister
@ 2017-04-01  4:23   ` Simon Glass
  2017-04-13 21:16     ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2017-04-01  4:23 UTC (permalink / raw)
  To: u-boot

On 30 March 2017 at 08:44, George McCollister
<george.mccollister@gmail.com> wrote:
> With Python 3.5.2 encode will throw an exception if val is a byte array.
> Decode it to a string first. This assumes it's utf-8, if it's not valid
> utf-8 it will throw an exception.
>
> Signed-off-by: George McCollister <george.mccollister@gmail.com>
> ---
>  tools/dtoc/fdt_util.py | 2 ++
>  1 file changed, 2 insertions(+)

Acked-by: Simon Glass <sjg@chromium.org>

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

* [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings
  2017-04-01  4:23 ` [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings Simon Glass
@ 2017-04-13 21:16   ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2017-04-13 21:16 UTC (permalink / raw)
  To: u-boot

On 31 March 2017 at 22:23, Simon Glass <sjg@chromium.org> wrote:
> On 30 March 2017 at 08:44, George McCollister
> <george.mccollister@gmail.com> wrote:
>> os.read() returns a byte array in Python 3.5.2 and needs to be converted
>> into a string. Check if the returned value is an instance of bytes and
>> if it is decode it as a utf-8 string. If it is not a utf-8 encoded string
>> the decoding may fail with an exception.
>>
>> Prior to this fix the comparisions check data == "" would fail when data
>> was b'' and would cause an infinite memory leaking loop. joins would
>> also fail with an exception below but due to the infinite loop it never
>> made it that far.
>>
>> Signed-off-by: George McCollister <george.mccollister@gmail.com>
>> ---
>>  tools/patman/cros_subprocess.py | 4 ++++
>>  1 file changed, 4 insertions(+)
>
> Acked-by: Simon Glass <sjg@chromium.org>


Applied to u-boot-dm, thanks!

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

* [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string
  2017-04-01  4:23   ` Simon Glass
@ 2017-04-13 21:16     ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2017-04-13 21:16 UTC (permalink / raw)
  To: u-boot

On 31 March 2017 at 22:23, Simon Glass <sjg@chromium.org> wrote:
> On 30 March 2017 at 08:44, George McCollister
> <george.mccollister@gmail.com> wrote:
>> With Python 3.5.2 encode will throw an exception if val is a byte array.
>> Decode it to a string first. This assumes it's utf-8, if it's not valid
>> utf-8 it will throw an exception.
>>
>> Signed-off-by: George McCollister <george.mccollister@gmail.com>
>> ---
>>  tools/dtoc/fdt_util.py | 2 ++
>>  1 file changed, 2 insertions(+)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!

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

end of thread, other threads:[~2017-04-13 21:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-30 14:44 [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings George McCollister
2017-03-30 14:44 ` [U-Boot] [PATCH 2/2] dtoc: Decode val if it's a byte string George McCollister
2017-04-01  4:23   ` Simon Glass
2017-04-13 21:16     ` Simon Glass
2017-04-01  4:23 ` [U-Boot] [PATCH 1/2] patman: Convert byte arrays to strings Simon Glass
2017-04-13 21:16   ` Simon Glass

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.