From 22adaea1ee87bee503123b014adb729e6ad669ae Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Mon, 27 Nov 2017 09:57:37 +0000 Subject: [PATCH] Truncate negative lengths to zero --- lib/libc/stdio/xprintf_hexdump.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/libc/stdio/xprintf_hexdump.c b/lib/libc/stdio/xprintf_hexdump.c index 73f98a8fb53f..0b7dfb3ff221 100644 --- a/lib/libc/stdio/xprintf_hexdump.c +++ b/lib/libc/stdio/xprintf_hexdump.c @@ -50,6 +50,7 @@ int __printf_render_hexdump(struct __printf_io *io, const struct printf_info *pi, const void *const *arg) { unsigned char *p; + int i; unsigned u, l, j, a; char buf[100], *q; int ret; @@ -59,7 +60,10 @@ __printf_render_hexdump(struct __printf_io *io, const struct printf_info *pi, co else l = 16; p = *((unsigned char **)arg[0]); - u = *((unsigned *)arg[1]); + i = *((int *)arg[1]); + if (i < 0) + i = 0; + u = i; ret = 0; a = 0;