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.

Suggested by @grigorescu
Related to #1134.

(cherry picked from commit c357829)
Signed-off-by: Bruce A. Mah <bmah@es.net>
  • Loading branch information
bmah888 committed Apr 14, 2021
1 parent 6b266c7 commit 466f4c1
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 466f4c1

Please sign in to comment.