Skip to content

Commit 3291a16

Browse files
authored
Merge pull request #1929 from esnet/bmah-no-sprintf
Replace sprintf() calls in original iperf3 code
2 parents 156953d + cf53d6c commit 3291a16

File tree

4 files changed

+5
-21
lines changed

4 files changed

+5
-21
lines changed

src/iperf_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,7 +3790,7 @@ iperf_print_intermediate(struct iperf_test *test)
37903790
/* Print stream role just for bidirectional mode. */
37913791

37923792
if (test->mode == BIDIRECTIONAL) {
3793-
sprintf(mbuf, "[%s-%s]", stream_must_be_sender?"TX":"RX", test->role == 'c'?"C":"S");
3793+
snprintf(mbuf, sizeof(mbuf), "[%s-%s]", stream_must_be_sender?"TX":"RX", test->role == 'c'?"C":"S");
37943794
} else {
37953795
mbuf[0] = '\0';
37963796
zbuf[0] = '\0';
@@ -3992,7 +3992,7 @@ iperf_print_results(struct iperf_test *test)
39923992
/* Print stream role just for bidirectional mode. */
39933993

39943994
if (test->mode == BIDIRECTIONAL) {
3995-
sprintf(mbuf, "[%s-%s]", stream_must_be_sender?"TX":"RX", test->role == 'c'?"C":"S");
3995+
snprintf(mbuf, sizeof(mbuf), "[%s-%s]", stream_must_be_sender?"TX":"RX", test->role == 'c'?"C":"S");
39963996
} else {
39973997
mbuf[0] = '\0';
39983998
}
@@ -4484,7 +4484,7 @@ print_interval_results(struct iperf_test *test, struct iperf_stream *sp, cJSON *
44844484
double bandwidth, lost_percent;
44854485

44864486
if (test->mode == BIDIRECTIONAL) {
4487-
sprintf(mbuf, "[%s-%s]", sp->sender?"TX":"RX", test->role == 'c'?"C":"S");
4487+
snprintf(mbuf, sizeof(mbuf), "[%s-%s]", sp->sender?"TX":"RX", test->role == 'c'?"C":"S");
44884488
} else {
44894489
mbuf[0] = '\0';
44904490
zbuf[0] = '\0';

src/iperf_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ long get_rttvar(struct iperf_interval_results *irp);
332332
long get_pmtu(struct iperf_interval_results *irp);
333333
long get_reorder(struct iperf_interval_results *irp);
334334
void print_tcpinfo(struct iperf_test *test);
335-
void build_tcpinfo_message(struct iperf_interval_results *r, char *message);
336335

337336
int iperf_set_send_state(struct iperf_test *test, signed char state);
338337
void iperf_check_throttle(struct iperf_stream *sp, struct iperf_time *nowP);

src/iperf_auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void sha256(const char *string, char outputBuffer[65])
6060
int i = 0;
6161
for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
6262
{
63-
sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
63+
snprintf(outputBuffer + (i * 2), 3, "%02x", hash[i]);
6464
}
6565
outputBuffer[64] = 0;
6666
}
@@ -74,7 +74,7 @@ int check_authentication(const char *username, const char *password, const time_
7474

7575
char passwordHash[65];
7676
char salted[strlen(username) + strlen(password) + 3];
77-
sprintf(salted, "{%s}%s", username, password);
77+
snprintf(salted, sizeof(salted), "{%s}%s", username, password);
7878
sha256(&salted[0], passwordHash);
7979

8080
char *s_username, *s_password;

src/tcp_info.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,3 @@ get_reorder(struct iperf_interval_results *irp)
235235
#endif
236236
}
237237

238-
/*************************************************************/
239-
void
240-
build_tcpinfo_message(struct iperf_interval_results *r, char *message)
241-
{
242-
#if defined(linux) && defined(TCP_INFO)
243-
sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh,
244-
r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked,
245-
r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets,
246-
r->tcpInfo.tcpi_rtt, r->tcpInfo.tcpi_reordering);
247-
#endif
248-
#if (defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO)
249-
sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd,
250-
r->tcpInfo.tcpi_rcv_space, r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rtt);
251-
#endif
252-
}

0 commit comments

Comments
 (0)