From bb34e7d94cd9e13de33b5b97c5e4ccff59714970 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 22 Feb 2022 23:24:09 +0000 Subject: [PATCH] Check asprintf() return to avoid crashing in strcmp(). ok deraadt millert --- usr.bin/seq/seq.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c index 99068291609..e44b9df7a32 100644 --- a/usr.bin/seq/seq.c +++ b/usr.bin/seq/seq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: seq.c,v 1.3 2022/02/22 16:14:38 rob Exp $ */ +/* $OpenBSD: seq.c,v 1.4 2022/02/22 23:24:09 tb Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -195,8 +195,9 @@ 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) == -1 || + asprintf(&last_print, fmt, last) == -1) + err(1, "asprintf"); if (strcmp(cur_print, last_print) == 0 && cur != last_shown_value) { if (cur != first) fputs(sep, stdout); -- 2.20.1