Remaining linebuffer size (i.e., how many characters snprintf() is allowed to still add) should be `SNBUFFERSIZE-strlen(linebuffer)`, rather than `SNBUFFERSIZE-strlen(b)`, where b is the pointer to the *END* of linebuffer (and thus strlen(b) will always be 0, always telling snprintf() that it can still print SNBUFFERSIZE characters, even when linebuffer is already partially or totally filled. ---
Re-sending (after subscribing to iperf-users) b/c I need a mailing list link to reference in Bugzilla :) src/ReportOutputs.c | 50 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ReportOutputs.c b/src/ReportOutputs.c index 463aa913..6a03cb22 100644 --- a/src/ReportOutputs.c +++ b/src/ReportOutputs.c @@ -2638,7 +2638,7 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { int n; #if HAVE_DECL_TCP_WINDOW_CLAMP if (!isUDP(report->common) && isRxClamp(report->common)) { - n = snprintf(b, (SNBUFFERSIZE-strlen(b)), " (%s%d)", "clamp=", report->common->ClampSize); + n = snprintf(b, (SNBUFFERSIZE-strlen(linebuffer)), " (%s%d)", "clamp=", report->common->ClampSize); FAIL_exit((n < 0), "fail append clamp"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow clamp"); b += n; @@ -2646,57 +2646,57 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { #endif #if HAVE_DECL_TCP_NOTSENT_LOWAT if (!isUDP(report->common) && (report->common->socket > 0) && isWritePrefetch(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (%s%d)", "prefetch=", report->common->WritePrefetch); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (%s%d)", "prefetch=", report->common->WritePrefetch); FAIL_exit((n < 0), "fail append prefetch"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow prefetch"); b += n; } #endif if (isIsochronous(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (isoch)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (isoch)"); FAIL_exit((n < 0), "fail append isoch"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow isoch"); b += n; } if (isPeriodicBurst(report->common) && (report->common->ThreadMode != kMode_Client) && !isServerReverse(report->common)) { #if HAVE_FASTSAMPLING - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (burst-period=%0.4fs)", (1.0 / report->common->FPS)); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (burst-period=%0.4fs)", (1.0 / report->common->FPS)); #else - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (burst-period=%0.2fs)", (1.0 / report->common->FPS)); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (burst-period=%0.2fs)", (1.0 / report->common->FPS)); #endif FAIL_exit((n < 0), "fail append burst"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow burst"); b += n; } if (isFullDuplex(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (full-duplex)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (full-duplex)"); FAIL_exit((n < 0), "fail append duplex"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow duplex"); b += n; } else if (isServerReverse(report->common) || isReverse(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (reverse)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (reverse)"); FAIL_exit((n < 0), "fail append reverse"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow reverse"); b += n; if (isFQPacing(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (fq)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (fq)"); FAIL_exit((n < 0), "fail append fq"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow fq"); b += n; } } if (isTxStartTime(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (epoch-start)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (epoch-start)"); FAIL_exit((n < 0), "fail append epoch"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow epoch"); b += n; } if (isBounceBack(report->common)) { if (isTcpQuickAck(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (bb w/quickack req/reply/hold=%d/%d/%d)", report->common->bbsize, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (bb w/quickack req/reply/hold=%d/%d/%d)", report->common->bbsize, \ report->common->bbreplysize, report->common->bbhold); } else { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (bb req/reply/hold=%d/%d/%d)", report->common->bbsize, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (bb req/reply/hold=%d/%d/%d)", report->common->bbsize, \ report->common->bbreplysize, report->common->bbhold); } FAIL_exit((n < 0), "fail append bb"); @@ -2704,19 +2704,19 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { b += n; } if (isL2LengthCheck(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (l2mode)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (l2mode)"); FAIL_exit((n < 0), "fail append l2"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow l2"); b += n; } if (isUDP(report->common) && isNoUDPfin(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (no-udp-fin)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (no-udp-fin)"); FAIL_exit((n < 0), "fail append ufin"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow ufin"); b += n; } if (isTripTime(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (trip-times)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (trip-times)"); FAIL_exit((n < 0), "fail append tt"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow tt"); b += n; @@ -2731,7 +2731,7 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { cca[len - 1] = '\0'; } if (rc != SOCKET_ERROR) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (%s)", cca); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (%s)", cca); FAIL_exit((n < 0), "fail append cca"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow cca"); b += n; @@ -2742,12 +2742,12 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { if (isOverrideTOS(report->common)) { n = 0; if (isFullDuplex(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (tos rx/tx=0x%x,dscp=%d,ecn=%d, /0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (tos rx/tx=0x%x,dscp=%d,ecn=%d, /0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS), \ report->common->RTOS, \ DSCP_VALUE(report->common->RTOS), ECN_VALUE(report->common->RTOS)); } else if (isReverse(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (tos rx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (tos rx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS)); } FAIL_exit((n < 0 ), "fail append o-tos"); @@ -2755,15 +2755,15 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { b += n; } else if (report->common->TOS) { if (isFullDuplex(report->common) || isBounceBack(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (tos rx/tx=0x%x,dscp=%d,ecn=%d/0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (tos rx/tx=0x%x,dscp=%d,ecn=%d/0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS), \ report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS)); } else if (isReverse(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (tos rx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (tos rx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS)); } else { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (tos tx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (tos tx=0x%x,dscp=%d,ecn=%d)", report->common->TOS, \ DSCP_VALUE(report->common->TOS), ECN_VALUE(report->common->TOS)); } FAIL_exit((n < 0), "fail append tos"); @@ -2772,7 +2772,7 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { } if (isEnhanced(report->common) || isPeerVerDetect(report->common)) { if (report->peerversion[0] != '\0') { - n = snprintf(b, SNBUFFERSIZE-strlen(b), "%s", report->peerversion); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), "%s", report->peerversion); FAIL_exit((n < 0), "fail append peer ver"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow peer ver"); b += n; @@ -2780,7 +2780,7 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { } #if HAVE_DECL_TCP_QUICKACK if (isTcpQuickAck(report->common) && !isBounceBack(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (qack)"); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (qack)"); FAIL_exit((n < 0), "fail append peer qack"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow peer qack"); b += n; @@ -2788,7 +2788,7 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { #endif #if HAVE_TCP_STATS if (!isUDP(report->common) && (report->tcpinitstats.isValid) && isEnhanced(report->common)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (icwnd/mss/irtt=%" PRIdMAX "/%" PRIuLEAST32 "/%" PRIuLEAST32 ")", \ + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (icwnd/mss/irtt=%" PRIdMAX "/%" PRIuLEAST32 "/%" PRIuLEAST32 ")", \ report->tcpinitstats.cwnd, report->tcpinitstats.mss_negotiated, report->tcpinitstats.rtt); FAIL_exit((n < 0), "fail append tcpstats"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow tcpstats"); @@ -2802,9 +2802,9 @@ void reporter_print_connection_report (struct ConnectionInfo *report) { iperf_formattime(timestr, sizeof(timestr), report->connect_timestamp, \ (isEnhanced(report->common) ? Milliseconds : Seconds), isUTC(report->common), YearThruSecTZ); if (!isUDP(report->common) && (report->common->ThreadMode == kMode_Client) && (report->tcpinitstats.connecttime > 0)) { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " (ct=%4.2f ms) on %s", report->tcpinitstats.connecttime, timestr); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " (ct=%4.2f ms) on %s", report->tcpinitstats.connecttime, timestr); } else { - n = snprintf(b, SNBUFFERSIZE-strlen(b), " on %s", timestr); + n = snprintf(b, SNBUFFERSIZE-strlen(linebuffer), " on %s", timestr); } FAIL_exit((n < 0), "fail append ct"); FAIL_exit((strlen(linebuffer) >= SNBUFFERSIZE), "buffer overflow ct"); -- 2.47.0 _______________________________________________ Iperf-users mailing list Iperf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iperf-users