vsprintf: Handle NULL with %pU
authorSimon Glass <sjg@chromium.org>
Mon, 18 Jun 2018 14:08:20 +0000 (08:08 -0600)
committerAlexander Graf <agraf@suse.de>
Wed, 25 Jul 2018 12:57:44 +0000 (14:57 +0200)
At present a NULL pointer passed to printf for a %pU argument will cause
U-Boot to access memory at 0. Fix this by adding a check, and print
"(null)" instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alexander Graf <agraf@suse.de>
[agraf: s/(null)/<NULL>/]
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/vsprintf.c

index 8b1b29fb5aa75278762a4c1222481fb42c0855c3..914fbd30cbc0f05dba95cf5b1dd4a2ac9f52f5ea 100644 (file)
@@ -407,7 +407,10 @@ static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
                break;
        }
 
-       uuid_bin_to_str(addr, uuid, str_format);
+       if (addr)
+               uuid_bin_to_str(addr, uuid, str_format);
+       else
+               strcpy(uuid, "<NULL>");
 
        return string(buf, end, uuid, field_width, precision, flags);
 }