Skip to content

Commit

Permalink
Make sure we don't pass in a negative buffer size.
Browse files Browse the repository at this point in the history
In theory this check should always succeed, given the relative
buffer sizes as currently coded.
  • Loading branch information
bmah888 authored and hanvari committed Jul 3, 2021
1 parent 7155dab commit 7bf6ebe
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4571,12 +4571,15 @@ iperf_printf(struct iperf_test *test, const char* format, ...)
return r0;
r += r0;
}
va_start(argp, format);
r0 = vsnprintf(linebuffer + r, sizeof(linebuffer) - r, format, argp);
va_end(argp);
if (r0 < 0)
return r0;
r += r0;
/* Should always be true as long as sizeof(ct) < sizeof(linebuffer) */
if (r < sizeof(linebuffer)) {
va_start(argp, format);
r0 = vsnprintf(linebuffer + r, sizeof(linebuffer) - r, format, argp);
va_end(argp);
if (r0 < 0)
return r0;
r += r0;
}
fprintf(test->outfile, "%s", linebuffer);

if (test->role == 's' && iperf_get_test_get_server_output(test)) {
Expand Down

0 comments on commit 7bf6ebe

Please sign in to comment.