From 94c4f663bab58ec07584786dd76866011d5b2506 Mon Sep 17 00:00:00 2001 From: Mariusz Zaborski Date: Fri, 30 Sep 2022 19:36:04 +0200 Subject: [PATCH] seq: fix potential NULL ptr reference asprintf(3) allocates memory, and there isn't any guarantee of success. MFC after: 2 weeks Obtained from: OpenBSD --- usr.bin/seq/seq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c index 7559dbd9ce20d5..47ba0b7ce3afd5 100644 --- a/usr.bin/seq/seq.c +++ b/usr.bin/seq/seq.c @@ -199,8 +199,12 @@ main(int argc, char *argv[]) * loop held true due to a rounding error and we still need to print * 'last'. */ - asprintf(&cur_print, fmt, cur); - asprintf(&last_print, fmt, last); + if (asprintf(&cur_print, fmt, cur) < 0) { + err(1, "asprintf"); + } + if (asprintf(&last_print, fmt, last) < 0) { + err(1, "asprintf"); + } if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) { fputs(last_print, stdout); fputs(sep, stdout);