From 063e8a8deaa89ca35ce6795f216c870e2df0743d Mon Sep 17 00:00:00 2001 From: liwugang Date: Thu, 4 Apr 2019 18:45:59 +0800 Subject: 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 --- toys/other/stat.c | 1 + 1 file changed, 1 insertion(+) (limited to 'toys') 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); -- cgit v1.2.3