diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2009-03-19 12:53:57 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2009-03-19 12:53:57 +0000 |
commit | 10ae1a84d0e83a6af8629a1e54d597931591ae67 (patch) | |
tree | f2f72c7ae157d4014e5ed0664e11755c5dfa169a | |
parent | ea0fbc95143f2097845b8a7ad6e00a3d2f023ecc (diff) | |
download | coreboot-10ae1a84d0e83a6af8629a1e54d597931591ae67.tar.gz coreboot-10ae1a84d0e83a6af8629a1e54d597931591ae67.tar.bz2 coreboot-10ae1a84d0e83a6af8629a1e54d597931591ae67.zip |
This patch tries to make printk more readable and reliable.
Base 16 number printing used digits[33] instead of the more readable 'x'
for the "0x" prefix. That means you have to look up an array just to
find out what the code does. Change it.
We already write "<NULL>" if printk gets a NULL pointer as string
argument. Introduce "<near NULL>" for string arguments with addresses
below 0x400. This error happened in the past when dereferencing a struct
member with a string and the struct had the address NULL.
Check if all to-be-printed characters in the string are indeed
printable. The idea is to catch garbage strings from stray pointers and
print "<non-ASCII characters>" instead.
If a string contains characters outside classic ASCII printable stuff,
this will trigger. An example would be characters with diacritic marks
like äöüéăçőč.
Then again, I don't see localized versions of coreboot on the horizon.
Maybe for payloads, but not for coreboot itself.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Peter Stuge <peter@stuge.se>
git-svn-id: svn://coreboot.org/repository/coreboot-v3@1158 f3766cd6-281f-0410-b1cd-43a5c92072e9
-rw-r--r-- | lib/vtxprintf.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/vtxprintf.c b/lib/vtxprintf.c index 792d511e8cb1..bc3621b91b0d 100644 --- a/lib/vtxprintf.c +++ b/lib/vtxprintf.c @@ -16,6 +16,7 @@ #define isdigit(c) ((c) >= '0' && (c) <= '9') #define is_digit isdigit #define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) +#define isprint(c) ((c) == '\n' || ((c) >= ' ' && (c) <= '~')) static int skip_atoi(const char **s) { @@ -87,7 +88,7 @@ static int number(void (*tx_byte)(unsigned char byte, void *arg), void *arg, tx_byte('0', arg), count++; else if (base==16) { tx_byte('0', arg), count++; - tx_byte(digits[33], arg), count++; + tx_byte('x', arg), count++; } } if (!(type & LEFT)) @@ -194,9 +195,15 @@ int vtxprintf(void (*tx_byte)(unsigned char byte, void *arg), void *arg, const c s = va_arg(args, char *); if (!s) s = "<NULL>"; + /* Catch almost-NULL pointers as well */ + if ((size_t)s < 0x400) + s = "<near NULL>"; len = strnlen(s, precision); + for (i = 0; i < len; ++i) + if (!isprint(*s[i])) + s = "<non-ASCII characters>"; if (!(flags & LEFT)) while (len < field_width--) tx_byte(' ', arg), count++; |