aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorliwugang <liwugang@xiaomi.com>2019-04-04 18:45:59 +0800
committerRob Landley <rob@landley.net>2019-04-04 14:08:16 -0500
commit063e8a8deaa89ca35ce6795f216c870e2df0743d (patch)
tree4a86898253d78765dd3515e5dc95d2b0f3bfceea /toys
parentaf2ee8dc9e35ee2148b9163827e81543b7e6ac1b (diff)
downloadtoybox-063e8a8deaa89ca35ce6795f216c870e2df0743d.tar.gz
stat: avoid null dereference.
When the specified format string has odd '%' in the end, the next_printf function will return null. Checking the result value before using it. Signed-off-by: liwugang <liwugang@xiaomi.com>
Diffstat (limited to 'toys')
-rw-r--r--toys/other/stat.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/toys/other/stat.c b/toys/other/stat.c
index d828534c..22b1b833 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -198,6 +198,7 @@ void stat_main(void)
if (*f != '%') putchar(*f);
else {
f = next_printf(f, &TT.pattern);
+ if (!f) error_exit("bad -c \"%s\"", format);
TT.patlen = f-TT.pattern;
if (TT.patlen>99) error_exit("bad %s", TT.pattern);
if (*f == 'n') strout(TT.file);