diff options
author | liwugang <liwugang@xiaomi.com> | 2019-04-04 18:45:59 +0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-04-04 14:08:16 -0500 |
commit | 063e8a8deaa89ca35ce6795f216c870e2df0743d (patch) | |
tree | 4a86898253d78765dd3515e5dc95d2b0f3bfceea | |
parent | af2ee8dc9e35ee2148b9163827e81543b7e6ac1b (diff) | |
download | toybox-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>
-rw-r--r-- | toys/other/stat.c | 1 |
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); |