Skip to content

Commit

Permalink
seq: fix potential NULL ptr reference
Browse files Browse the repository at this point in the history
asprintf(3) allocates memory, and there isn't any guarantee of success.

MFC after:	2 weeks
Obtained from:  OpenBSD
  • Loading branch information
oshogbo committed Oct 1, 2022
1 parent c5e957a commit 94c4f66
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions usr.bin/seq/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 94c4f66

Please sign in to comment.