diff options
author | Evan Green <evgreen@chromium.org> | 2019-10-01 14:26:29 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-05 00:47:59 +0000 |
commit | 47b264c6eb5074f74dac2ed3d88e7b9e4e6d3139 (patch) | |
tree | 188246705a36af80ba1ba466914c5f20f9bdb3c5 /test | |
parent | e77ccb89c1b74a9ba3be47072d35e3e148d2a469 (diff) | |
download | chrome-ec-47b264c6eb5074f74dac2ed3d88e7b9e4e6d3139.tar.gz |
printf: Deprecate %l
The semantics of %l changed during the enabling of compile-time
printf format checking. Old firmware branches will treat something
like %lx as a 64-bit value, but new code on master will enforce at
compile-time that a long (32-bits on our ECs) is passed in as the
argument. This creates a dangerous and difficult to notice situation
if the following code is cherry-picked from master into an old
firmware branch:
printf("%lx %s", myval32, mystr);
On master, this behaves correctly. On the old firmware branch, this
would swallow myval32 and mystr for %lx, and then %s would grab a
random stack pointer and print a string from it.
Deprecating %l is our mechanism for keeping such a printf from
creeping into master in the future. Obviously we can't protect against
someone that checks in code that's never tested, but anyone who tests
a printf with %l in it will notice their printf comes out with ERROR
instead of what they want.
BUG=chromium:984041
TEST=make -j buildall
BRANCH=None
Change-Id: I0267430363af7954c2ec5d2c45222759fe0ec2c1
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1834604
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/printf.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/printf.c b/test/printf.c index c521590440..43f4125e0c 100644 --- a/test/printf.c +++ b/test/printf.c @@ -183,6 +183,20 @@ test_static int test_vsnprintf_int(void) T(expect_success("5e", "%x", 0X5E)); T(expect_success("5E", "%X", 0X5E)); + /* + * %l is deprecated on 32-bit systems (see crbug.com/984041), but is + * is still functional on 64-bit systems. + */ + if (sizeof(long) == sizeof(uint32_t)) { + T(expect_success(err_str, "%lx", 0x7b)); + T(expect_success(err_str, "%08lu", 0x7b)); + T(expect_success("13ERROR", "%d%lu", 13, 14)); + } else { + T(expect_success("7b", "%lx", 0x7b)); + T(expect_success("00000123", "%08lu", 123)); + T(expect_success("131415", "%d%lu%d", 13, 14L, 15)); + } + return EC_SUCCESS; } |