Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r788 committed - Replacing sprintf with snprintf

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r788 committed - Replacing sprintf with snprintf


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r788 committed - Replacing sprintf with snprintf
  • Date: Mon, 05 Nov 2012 18:32:02 +0000

Revision: 788
Author:

Date: Mon Nov 5 10:30:55 2012
Log: Replacing sprintf with snprintf
http://code.google.com/p/ndt/source/detail?r=788

Modified:
/trunk/src/analyze.c
/trunk/src/fakewww.c
/trunk/src/genplot.c
/trunk/src/logging.c
/trunk/src/logging.h
/trunk/src/mrange.c
/trunk/src/mrange.h
/trunk/src/ndt_odbc.c
/trunk/src/test_c2s_srv.c
/trunk/src/test_meta_clt.c
/trunk/src/test_meta_srv.c
/trunk/src/test_mid_clt.c
/trunk/src/test_mid_srv.c
/trunk/src/test_s2c_clt.c
/trunk/src/test_s2c_srv.c
/trunk/src/test_sfw_clt.c
/trunk/src/test_sfw_srv.c
/trunk/src/testoptions.c
/trunk/src/testoptions.h
/trunk/src/tr-mkmap.c
/trunk/src/tr-tree.h
/trunk/src/viewtrace.c
/trunk/src/web100-admin.c
/trunk/src/web100-pcap.c
/trunk/src/web100-util.c
/trunk/src/web100srv.c
/trunk/src/web100srv.h

=======================================
--- /trunk/src/analyze.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/analyze.c Mon Nov 5 10:30:55 2012
@@ -184,83 +184,83 @@
}
switch (c2s_linkspeed_data) {
case -2:
- sprintf(btlneck, "Insufficent Data");
+ snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
break;
case -1:
- sprintf(btlneck, "a System Fault");
+ snprintf(btlneck, sizeof(btlneck), "a System Fault");
break;
case 0:
- sprintf(btlneck, "the Round Trip Time");
+ snprintf(btlneck, sizeof(btlneck), "the Round Trip Time");
break;
case 1:
- sprintf(btlneck, "a 'Dial-up modem' connection");
+ snprintf(btlneck, sizeof(btlneck), "a 'Dial-up modem'
connection");
break;
case 2:
if ((c2sspd / s2cspd > .8) && (c2sspd / s2cspd < 1.2)
&& (c2sspd > 1000))
- sprintf(btlneck, "a 'T1' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a 'T1' subnet");
else {
if ((tail[3] > 1) || (s2c_linkspeed_ack == 3))
- sprintf(btlneck, "a 'Cable Modem'
connection");
+ snprintf(btlneck, sizeof(btlneck), "a 'Cable
Modem' connection");
else
- sprintf(btlneck, "a 'DSL' connection");
+ snprintf(btlneck, sizeof(btlneck), "a 'DSL'
connection");
}
break;
case 3:
if (linkcnt == 16)
- sprintf(btlneck, "a T1 + subnet");
+ snprintf(btlneck, sizeof(btlneck), "a T1 + subnet");
else
- sprintf(btlneck, "an 'Ethernet' subnet");
+ snprintf(btlneck, sizeof(btlneck), "an 'Ethernet'
subnet");
break;
case 4:
if (linkcnt == 16)
- sprintf(btlneck, "a IEEE 802.11b Wifi subnet");
+ snprintf(btlneck, sizeof(btlneck), "a IEEE 802.11b Wifi
subnet");
else
- sprintf(btlneck, "a 'T3/DS-3' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a 'T3/DS-3'
subnet");
break;
case 5:
if (linkcnt == 16)
- sprintf(btlneck, "a Wifi + subnet");
+ snprintf(btlneck, sizeof(btlneck), "a Wifi + subnet");
else
- sprintf(btlneck, "a 'FastEthernet' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a 'FastEthernet'
subnet");
break;
case 6:
if (linkcnt == 16)
- sprintf(btlneck, "a Ethernet subnet");
+ snprintf(btlneck, sizeof(btlneck), "a Ethernet
subnet");
else
- sprintf(btlneck, "an 'OC-12' subnet");
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-12'
subnet");
break;
case 7:
if (linkcnt == 16)
- sprintf(btlneck, "a T3/DS3 subnet");
+ snprintf(btlneck, sizeof(btlneck), "a T3/DS3 subnet");
else
- sprintf(btlneck, "a 'Gigabit Ethernet' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a 'Gigabit Ethernet'
subnet");
break;
case 8:
if (linkcnt == 16)
- sprintf(btlneck, "a FastEthernet subnet");
+ snprintf(btlneck, sizeof(btlneck), "a FastEthernet
subnet");
else
- sprintf(btlneck, "an 'OC-48' subnet");
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-48'
subnet");
break;
case 9:
if (linkcnt == 16)
- sprintf(btlneck, "a OC-12 subnet");
+ snprintf(btlneck, sizeof(btlneck), "a OC-12 subnet");
else
- sprintf(btlneck, "a '10 Gigabit Enet' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet'
subnet");
break;
case 10:
if (linkcnt == 16)
- sprintf(btlneck, "a Gigabit Ethernet subnet");
+ snprintf(btlneck, sizeof(btlneck), "a Gigabit Ethernet
subnet");
else
- sprintf(btlneck, "Retransmissions");
+ snprintf(btlneck, sizeof(btlneck), "Retransmissions");
case 11:
- sprintf(btlneck, "an 'OC-48' subnet");
+ snprintf(btlneck, sizeof(btlneck), "an 'OC-48' subnet");
break;
case 12:
- sprintf(btlneck, "a '10 Gigabit Enet' subnet");
+ snprintf(btlneck, sizeof(btlneck), "a '10 Gigabit Enet'
subnet");
break;
case 13:
- sprintf(btlneck, "Retransmissions");
+ snprintf(btlneck, sizeof(btlneck), "Retransmissions");
break;
}
/* Calculate some values */
@@ -498,14 +498,14 @@
log_init(argv[0], debug);

if (LogFileName == NULL) {
- sprintf(tmpstr, "%s/%s", BASEDIR, LOGFILE);
+ snprintf(tmpstr, sizeof(tmpstr), "%s/%s", BASEDIR, LOGFILE);
LogFileName = tmpstr;
}
log_println(1, "log file = %s", LogFileName);

//TODO do we need protocol log file in analyze????
if (ProtoLogFileName == NULL) {
- sprintf(tmpstr, "%s/%s", BASEDIR, PROTOLOGFILE);
+ snprintf(tmpstr, 256, "%s/%s", BASEDIR, PROTOLOGFILE);
ProtoLogFileName = tmpstr;
}
log_println(1, "log file = %s", ProtoLogFileName);
=======================================
--- /trunk/src/fakewww.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/fakewww.c Mon Nov 5 10:30:55 2012
@@ -85,10 +85,11 @@
char* basedir = BASEDIR;

char* DefaultTree = NULL;
-static char dtfn[256];
+#define DTFN_STRLEN 256
+static char dtfn[DTFN_STRLEN];
#ifdef AF_INET6
char* DefaultTree6 = NULL;
-static char dt6fn[256];
+static char dt6fn[DTFN_STRLEN];
#endif

int usesyslog = 0;
@@ -232,13 +233,13 @@
}

if (DefaultTree == NULL) {
- sprintf(dtfn, "%s/%s", BASEDIR, DFLT_TREE);
+ snprintf(dtfn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE);
DefaultTree = dtfn;
}

#ifdef AF_INET6
if (DefaultTree6 == NULL) {
- sprintf(dt6fn, "%s/%s", BASEDIR, DFLT_TREE6);
+ snprintf(dt6fn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE6);
DefaultTree6 = dt6fn;
}
#endif
@@ -432,24 +433,28 @@
struct sockaddr* csaddr;
csaddr = I2AddrSAddr(addr, NULL);
if (csaddr->sa_family == AF_INET) { /* make
the IPv4 find */
+ char ip_str[16];
struct sockaddr_in* cli_addr =
(struct sockaddr_in*) csaddr;
find_route(cli_addr->sin_addr.s_addr,
IPlist, max_ttl);
for (i = 0; IPlist[i] !=
cli_addr->sin_addr.s_addr; i++) {
- sprintf(p, "%u.%u.%u.%u",
IPlist[i] & 0xff,
- (IPlist[i] >> 8)
& 0xff,
- (IPlist[i] >> 16)
& 0xff,
- (IPlist[i] >> 24)
& 0xff);
- log_println(4, "loop IPlist[%d] =
%s", i, p);
+ snprintf(ip_str, sizeof(ip_str),
"%u.%u.%u.%u",
+ IPlist[i] & 0xff,
+ (IPlist[i] >> 8) &
0xff,
+ (IPlist[i] >> 16) &
0xff,
+ (IPlist[i] >> 24) &
0xff);
+ log_println(4, "loop IPlist[%d] =
%s", i, ip_str);
if (i == max_ttl) {
log_println(4, "Oops,
destination not found!");
break;
}
}
/* print out last item on list */
- sprintf(p, "%u.%u.%u.%u", IPlist[i] &
0xff,
- (IPlist[i] >> 8) & 0xff,
(IPlist[i] >> 16) & 0xff,
- (IPlist[i] >> 24) &
0xff);
- log_println(4, "IPlist[%d] = %s", i,
p);
+ snprintf(ip_str, sizeof(ip_str),
"%u.%u.%u.%u",
+ IPlist[i] & 0xff,
+ (IPlist[i] >> 8) & 0xff,
+ (IPlist[i] >> 16) & 0xff,
+ (IPlist[i] >> 24) & 0xff);
+ log_println(4, "IPlist[%d] = %s", i,
ip_str);

srv_addr = find_compare(IPlist, i);

@@ -489,7 +494,7 @@

writen(sd, MsgRedir1,
strlen(MsgRedir1));
writen(sd, MsgRedir2,
strlen(MsgRedir2));
- sprintf(line,
"http://%u.%u.%u.%u:%s/tcpbw100.html";,
+ snprintf(line, sizeof(line),
"http://%u.%u.%u.%u:%s/tcpbw100.html";,
srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
(srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
port);
@@ -497,7 +502,7 @@
writen(sd, MsgRedir3,
strlen(MsgRedir3));
writen(sd, MsgRedir4,
strlen(MsgRedir4));
answerSize = strlen(MsgRedir4);
- sprintf(line,
"url=http://%u.%u.%u.%u:%s/tcpbw100.html";,
+ snprintf(line, sizeof(line), "url=http://%u.%u.%u.%u:%s/tcpbw100.html";,
srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
(srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
port);
@@ -505,8 +510,7 @@
answerSize += strlen(line);
writen(sd, MsgRedir5,
strlen(MsgRedir5));
answerSize += strlen(MsgRedir5);
- sprintf(line,
-
"href=\"http://%u.%u.%u.%u:%s/tcpbw100.html\"";,
+ snprintf(line, sizeof(line), "href=\"http://%u.%u.%u.%u:%s/tcpbw100.html\"";,
srv_addr & 0xff, (srv_addr
>> 8) & 0xff,
(srv_addr >> 16) & 0xff,
(srv_addr >> 24) & 0xff,
port);
@@ -572,17 +576,17 @@

writen(sd, MsgRedir1,
strlen(MsgRedir1));
writen(sd, MsgRedir2,
strlen(MsgRedir2));
- sprintf(line,
"http://[%s]:%s/tcpbw100.html";, onenodename, port);
+ snprintf(line, sizeof(line), "http://[%s]:%s/tcpbw100.html";, onenodename, port);
writen(sd, line, strlen(line));
writen(sd, MsgRedir3,
strlen(MsgRedir3));
writen(sd, MsgRedir4,
strlen(MsgRedir4));
answerSize = strlen(MsgRedir4);
- sprintf(line,
"url=http://[%s]:%s/tcpbw100.html";, onenodename, port);
+ snprintf(line, sizeof(line), "url=http://[%s]:%s/tcpbw100.html";, onenodename, port);
writen(sd, line, strlen(line));
answerSize += strlen(line);
writen(sd, MsgRedir5,
strlen(MsgRedir5));
answerSize += strlen(MsgRedir5);
- sprintf(line, "href=\"http://[%s]:%s/tcpbw100.html\"";, onenodename, port);
+ snprintf(line, sizeof(line), "href=\"http://[%s]:%s/tcpbw100.html\"";, onenodename, port);
writen(sd, line, strlen(line));
answerSize += strlen(line);
writen(sd, MsgRedir6,
strlen(MsgRedir6));
@@ -639,7 +643,7 @@
nodename, filename);
break;
}
- sprintf(htmlfile, "%s/%s", basedir, filename + 1);
+ snprintf(htmlfile, sizeof(htmlfile), "%s/%s", basedir,
filename + 1);
fd = open(htmlfile, 0); /* open file for read */
if (fd < 0) {
close(fd);
@@ -678,8 +682,7 @@
setenv("SERVER_NAME", onenodename, 1);
setenv("REMOTE_HOST", nodename, 1);
setenv("REMOTE_ADDR", "207.75.164.153", 1);
- system(
- "/usr/bin/perl /usr/local/ndt/traceroute.pl > /tmp/rac-traceroute.pl");
+ system("/usr/bin/perl /usr/local/ndt/traceroute.pl > /tmp/rac-traceroute.pl");
close(fd);
fd = open("/tmp/rac-traceroute.pl", 0);
}
=======================================
--- /trunk/src/genplot.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/genplot.c Mon Nov 5 10:30:55 2012
@@ -587,7 +587,7 @@
}

for (j = optind; j < argc; j++) {
- sprintf(fn, "%s", argv[j]);
+ snprintf(fn, sizeof(fn), "%s", argv[j]);
if ((log = web100_log_open_read(fn)) == NULL) {
web100_perror("web100_log_open_read");
exit(EXIT_FAILURE);
@@ -681,4 +681,3 @@

exit(0);
}
-
=======================================
--- /trunk/src/logging.c Mon Oct 29 10:56:28 2012
+++ /trunk/src/logging.c Mon Nov 5 10:30:55 2012
@@ -78,7 +78,7 @@
return ret;
}

- sprintf(dest_fn, "%s.gz", src_fn);
+ snprintf(dest_fn, sizeof(dest_fn), "%s.gz", src_fn);
if ((source = fopen(src_fn, "r")) == NULL) {
log_println(6, "zlib_def(): failed to open src file '%s' for
reading",
src_fn);
@@ -205,12 +205,12 @@
log_println(5, "PV: 1: NULL proto location =%s;\n",
ProtocolLogDirName);
return;
} else if (dirname[0] != '/') {
- sprintf(localstr, "%s/%s/", BASEDIR, dirname);
+ snprintf(localstr, sizeof(localstr), "%s/%s/", BASEDIR,
dirname);
ProtocolLogDirName = localstr;
log_println(5, "PV: 2: non-dir proto location. So=%s;\n",
dirname);
} //end protocol dir name
else {
- sprintf(localstr, "%s", dirname);
+ snprintf(localstr, sizeof(localstr), "%s", dirname);
ProtocolLogDirName = dirname;
log_println(5, "PV33: proto location=%s;\n",
ProtocolLogDirName);
}
@@ -244,7 +244,7 @@
void create_protolog_dir() {
if ( get_protocolloggingenabled() ) {
set_timestamp();
- sprintf(protocollogfilestore, "%s/", get_protologdir());
+ snprintf(protocollogfilestore, sizeof(protocollogfilestore), "%s/", get_protologdir());
log_println(5,"Creating protocol log directory=%s", protocollogfilestore);
create_named_logdir(protocollogfilestore, sizeof(protocollogfilestore), "", get_protocolloggingenabled());
set_protologdir(protocollogfilestore);
@@ -289,8 +289,7 @@
* @return The protocol log filename
*/

-char*
-get_protologfile(int socketNum, char *protologfilename) {
+char* get_protologfile(int socketNum, char *protologfilename, size_t filename_size) {
char localAddr[64]="", remoteAddr[64]="";
I2Addr tmp_addr = NULL;
size_t tmpstrlen = sizeof(localAddr);
@@ -308,7 +307,7 @@
I2AddrNodeName(tmp_addr, localAddr, &tmpstrlen);

// copy address into filename String
- sprintf(protologfilename, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
+ snprintf(protologfilename, filename_size, "%s/%s%s%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX,
localAddr, "_",remoteAddr, PROTOLOGSUFFIX, "\0");
//log_print(0, "Log file name ---%s---", protologfilename);

@@ -458,7 +457,7 @@
// make delimiters in message payload explicit
quote_delimiters(value, strlen(value), logmessage,
sizeof(logmessage));

- fp = fopen(get_protologfile(socketnum, tmplogname), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
if (fp == NULL) {
log_println(5,
"--Unable to open proto file while trying to
record msg: %s \n",
@@ -501,14 +500,14 @@
return;
}

- fp = fopen(get_protologfile(socketnum, tmplogname), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");
if (fp == NULL) {
log_println(
5,
"--Unable to open protocol log file while trying to record test status message: %s for the %s test \n",
teststatusdesc, currenttestname);
} else {
- sprintf(protomessage,
+ snprintf(protomessage, sizeof(protomessage),
" event=\"%s\", name=\"%s\", pid=\"%d\",
time=\"%s\"\n",
teststatusdesc, currenttestname, pid,
get_currenttime(isotime, sizeof(isotime)));
@@ -552,7 +551,7 @@
return;
}

- fp = fopen(get_protologfile(socketnum, tmplogname), "a");
+ fp = fopen(get_protologfile(socketnum, tmplogname, sizeof(tmplogname)), "a");

if (fp == NULL) {
log_println(
@@ -561,8 +560,7 @@
procstatusdesc, currentprocname);
} else {
log_println(8, " a0\n %s, %s, %s,%d", procstatusdesc,currentprocname,currenttestname,pid);
- sprintf(
- protomessage,
+ snprintf(protomessage, sizeof(protomessage),
" event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\",
time=\"%s\"\n",
procstatusdesc, currentprocname,
currenttestname, pid,
get_currenttime(isotime, sizeof(isotime)));
@@ -668,7 +666,7 @@

getMessageBodyFormat(type, len, msgbodytype, (char *) msg, logmessage, sizeof(logmessage));

- fp = fopen(get_protologfile(ctlSocket, protologfile), "a");
+ fp = fopen(get_protologfile(ctlSocket, protologfile, sizeof(protologfile)), "a");
if (fp == NULL) {
log_println(
5,
@@ -766,7 +764,7 @@
* @param Pointer to the string indicating the year
*/

-void get_YYYY(char *year) {
+void get_YYYY(char *year, size_t year_strlen) {

struct tm *result;
time_t now;
@@ -775,7 +773,7 @@
now = get_timestamp();
result = gmtime(&now);

- sprintf(year, "%d", 1900 + result->tm_year);
+ snprintf(year, year_strlen, "%d", 1900 + result->tm_year);
}

/**
@@ -784,7 +782,7 @@
* @param Pointer to the string indicating month
*/

-void get_MM(char *month) {
+void get_MM(char *month, size_t month_strlen) {

struct tm *result;
time_t now;
@@ -795,9 +793,9 @@
result = gmtime(&now);

if (1 + result->tm_mon < 10)
- sprintf(month, "0%d", 1 + result->tm_mon);
+ snprintf(month, month_strlen, "0%d", 1 + result->tm_mon);
else
- sprintf(month, "%d", 1 + result->tm_mon);
+ snprintf(month, month_strlen, "%d", 1 + result->tm_mon);
}

/**
@@ -806,7 +804,7 @@
* @param Pointer to the string indicating day
*/

-void get_DD(char *day) {
+void get_DD(char *day, size_t day_strlen) {

struct tm *result;
time_t now;
@@ -815,9 +813,9 @@
result = gmtime(&now);

if (result->tm_mday < 10)
- sprintf(day, "0%d", result->tm_mday);
+ snprintf(day, day_strlen, "0%d", result->tm_mday);
else
- sprintf(day, "%d", result->tm_mday);
+ snprintf(day, day_strlen, "%d", result->tm_mday);
}


@@ -832,43 +830,43 @@
char *fill_ISOtime(struct tm *result, char *isoTime, int isotimearrsize) {
char tmpstr[16];

- sprintf(isoTime, "%d", 1900 + result->tm_year);
+ snprintf(isoTime, isotimearrsize, "%d", 1900 + result->tm_year);
if (1 + result->tm_mon < 10)
- sprintf(tmpstr, "0%d", 1 + result->tm_mon);
+ snprintf(tmpstr, sizeof(tmpstr), "0%d", 1 + result->tm_mon);
else
- sprintf(tmpstr, "%d", 1 + result->tm_mon);
+ snprintf(tmpstr, sizeof(tmpstr), "%d", 1 + result->tm_mon);

strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_mday < 10)
- sprintf(tmpstr, "0%d", result->tm_mday);
+ snprintf(tmpstr, sizeof(tmpstr), "0%d", result->tm_mday);
else
- sprintf(tmpstr, "%d", result->tm_mday);
+ snprintf(tmpstr, sizeof(tmpstr), "%d", result->tm_mday);

strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_hour < 10)
- sprintf(tmpstr, "T0%d", result->tm_hour);
+ snprintf(tmpstr, sizeof(tmpstr), "T0%d", result->tm_hour);
else
- sprintf(tmpstr, "T%d", result->tm_hour);
+ snprintf(tmpstr, sizeof(tmpstr), "T%d", result->tm_hour);

strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_min < 10)
- sprintf(tmpstr, ":0%d", result->tm_min);
+ snprintf(tmpstr, sizeof(tmpstr), ":0%d", result->tm_min);
else
- sprintf(tmpstr, ":%d", result->tm_min);
+ snprintf(tmpstr, sizeof(tmpstr), ":%d", result->tm_min);

strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_sec < 10)
- sprintf(tmpstr, ":0%d", result->tm_sec);
+ snprintf(tmpstr, sizeof(tmpstr), ":0%d", result->tm_sec);
else
- sprintf(tmpstr, ":%d", result->tm_sec);
+ snprintf(tmpstr, sizeof(tmpstr), ":%d", result->tm_sec);

strlcat(isoTime, tmpstr, isotimearrsize);

- sprintf(tmpstr, ".%ldZ", get_utimestamp() * 1000);
+ snprintf(tmpstr, sizeof(tmpstr), ".%ldZ", get_utimestamp() * 1000);

strlcat(isoTime, tmpstr, isotimearrsize);
return isoTime;
@@ -988,8 +986,8 @@
if (snaplog) { // if snaplog is enabled, compress those into
.gz formats

// Try compressing C->S test snaplogs
- memset(filename, 0, 256);
- sprintf(filename, "%s/%s", dirpathstr,
meta.c2s_snaplog);
+ memset(filename, 0, sizeof(filename));
+ snprintf(filename, sizeof(filename), "%s/%s", dirpathstr, meta.c2s_snaplog);
if (zlib_def(filename) != 0)
log_println(0, "compression failed for file:%s:
%s.", filename,
dirpathstr);
@@ -997,8 +995,8 @@
strlcat(meta.c2s_snaplog, ".gz",
sizeof(meta.c2s_snaplog));

// Try compressing S->C test snaplogs
- memset(filename, 0, 256);
- sprintf(filename, "%s/%s", dirpathstr,
meta.s2c_snaplog);
+ memset(filename, 0, sizeof(filename));
+ snprintf(filename, sizeof(filename), "%s/%s", dirpathstr, meta.s2c_snaplog);
if (zlib_def(filename) != 0)
log_println(0, "compression failed for file
:%s", filename);
else
@@ -1010,8 +1008,8 @@

// Try compressing C->S test tcpdump.
// The tcpdump file extension is as specified in the "meta" data-structure
- memset(filename, 0, 256);
- sprintf(filename, "%s/%s", dirpathstr,
meta.c2s_ndttrace);
+ memset(filename, 0, sizeof(filename));
+ snprintf(filename, sizeof(filename), "%s/%s", dirpathstr, meta.c2s_ndttrace);
if (zlib_def(filename) != 0)
log_println(0, "compression failed for tcpdump
file %s =%s",
filename, meta.c2s_ndttrace);
@@ -1019,8 +1017,8 @@
strlcat(meta.c2s_ndttrace, ".gz",
sizeof(meta.c2s_ndttrace));

// Try compressing S->C test tcpdumps
- memset(filename, 0, 256);
- sprintf(filename, "%s/%s", dirpathstr,
meta.s2c_ndttrace);
+ memset(filename, 0, sizeof(filename));
+ snprintf(filename, sizeof(filename), "%s/%s", dirpathstr, meta.s2c_ndttrace);
if (zlib_def(filename) != 0)
log_println(0, "compression failed for tcpdump
file %s =%s",
filename, meta.s2c_ndttrace);
@@ -1030,8 +1028,8 @@

// If writing "cputime" file is enabled, compress those log
files too
if (cputime) {
- memset(filename, 0, 256);
- sprintf(filename, "%s/%s", dirpathstr, meta.CPU_time);
+ memset(filename, 0, sizeof(filename));
+ snprintf(filename, sizeof(filename), "%s/%s", dirpathstr, meta.CPU_time);
if (zlib_def(filename) != 0)
log_println(0, "compression failed");
else
@@ -1108,7 +1106,7 @@
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
mkdir(dirnamedestarg, 0755);
closedir(dp);
- get_YYYY(dir);
+ get_YYYY(dir, sizeof(dir));

strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
@@ -1116,7 +1114,7 @@
closedir(dp);

strlcat(dirnamedestarg, "/", destnamearrsize);
- get_MM(dir);
+ get_MM(dir, sizeof(dir));

strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
@@ -1124,7 +1122,7 @@
closedir(dp);

strlcat(dirnamedestarg, "/", destnamearrsize);
- get_DD(dir);
+ get_DD(dir, sizeof(dir));

strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
@@ -1132,7 +1130,7 @@
closedir(dp);

strlcat(dirnamedestarg, "/", destnamearrsize);
- sprintf(dir, "%s", finalsuffix);
+ snprintf(dir, sizeof(dir), "%s", finalsuffix);
strlcat(dirnamedestarg, dir, destnamearrsize);
log_println(5, "end named_log_create %s", dirnamedestarg);
}
@@ -1163,7 +1161,7 @@
I2AddrNodeName(sockAddr, namebuf, &namebuflen);
socketaddrport = I2AddrPort(sockAddr);

- sprintf(dir, "%s_%s:%d.%s", get_ISOtime(isoTime, sizeof(isoTime)), namebuf,
+ snprintf(dir, sizeof(dir), "%s_%s:%d.%s", get_ISOtime(isoTime, sizeof(isoTime)), namebuf,
socketaddrport, finalsuffix);
strlcpy(finalsuffix, dir, finalsuffixsize);

=======================================
--- /trunk/src/logging.h Mon Oct 29 10:56:28 2012
+++ /trunk/src/logging.h Mon Nov 5 10:30:55 2012
@@ -38,9 +38,9 @@
long int get_utimestamp();
char * get_ISOtime(char * isoTime, int isoTimeArrSize);
char *get_currenttime(char *isoTime, int isotimearrsize);
-void get_YYYY(char * year);
-void get_MM(char * month);
-void get_DD(char * day);
+void get_YYYY(char * year, size_t year_strlen);
+void get_MM(char * month, size_t month_strlen);
+void get_DD(char * day, size_t day_strlen);
char * DataDirName;

int zlib_def(char *src_fn);
@@ -85,7 +85,7 @@
void set_protologdir(char* dirname);
void set_protologfile(char* client_ip, char *protologfileparam);
char*
-get_protologfile(int socketNum, char *protologfilename) ;
+get_protologfile(int socketNum, char *protologfilename, size_t filename_size) ;
char* get_protologdir();
void enableprotocollogging();
char *createprotologfilename(char* client_ip, char* textappendarg);
=======================================
--- /trunk/src/mrange.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/mrange.c Mon Nov 5 10:30:55 2012
@@ -101,7 +101,7 @@
*/

char*
-mrange_next(char* port) {
+mrange_next(char* port, size_t port_strlen) {
int val;
Range* ptr;

@@ -109,7 +109,7 @@

if (check_rint(port, &val, 0, MAX_TCP_PORT)) { // check if valid
log_println(0, "WARNING: invalid port number");
- sprintf(port, RESERVED_PORT);
+ snprintf(port, port_strlen, RESERVED_PORT);
return port;
}
val++;
@@ -118,13 +118,13 @@
while (ptr != NULL) { // While there is some data
if ((val >= ptr->min) && (val <= ptr->max)) { //
check range

// and return port if valid
- sprintf(port, "%d", val);
+ snprintf(port, port_strlen, "%d", val);
return port;
}
ptr = ptr->next;
}
val++;
}
- sprintf(port, RESERVED_PORT);
+ snprintf(port, port_strlen, RESERVED_PORT);
return port;
}
=======================================
--- /trunk/src/mrange.h Fri Aug 18 03:16:24 2006
+++ /trunk/src/mrange.h Mon Nov 5 10:30:55 2012
@@ -10,6 +10,6 @@
#define _JS_MRANGE_H

int mrange_parse(char* text);
-char* mrange_next(char* port);
+char* mrange_next(char* port, size_t port_strlen);

#endif
=======================================
--- /trunk/src/ndt_odbc.c Tue Sep 25 06:49:57 2012
+++ /trunk/src/ndt_odbc.c Mon Nov 5 10:30:55 2012
@@ -144,7 +144,7 @@
char loginstring[1024];

log_println(1, "Initializing DB with DSN='%s', UID='%s', PWD=%s", dsn, uid, pwd ? "yes" : "no");
- sprintf(createTableStmt, "%s%s%s%s", ctStmt_1, ctStmt_2, ctStmt_3, ctStmt_4);
+ snprintf(createTableStmt, sizeof(createTableStmt), "%s%s%s%s", ctStmt_1, ctStmt_2, ctStmt_3, ctStmt_4);

// Allocate an environment handle
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
@@ -333,4 +333,3 @@
log_println(0," A float value you tried to insert into the DB was NaN");
}
}
-
=======================================
--- /trunk/src/test_c2s_srv.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/test_c2s_srv.c Mon Nov 5 10:30:55 2012
@@ -115,9 +115,9 @@
// Determine port to be used. Compute based on options set
earlier
// by reading from config file, or use default port2 (3002).
if (testOptions->c2ssockport) {
- sprintf(listenc2sport, "%d",
testOptions->c2ssockport);
+ snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->c2ssockport);
} else if (testOptions->mainport) {
- sprintf(listenc2sport, "%d", testOptions->mainport +
1);
+ snprintf(listenc2sport, sizeof(listenc2sport), "%d", testOptions->mainport + 1);
}

if (testOptions->multiple) {
@@ -126,11 +126,11 @@

// attempt to bind to a new port and obtain address structure with details of listening port
while (c2ssrv_addr == NULL) {
- c2ssrv_addr =
- CreateListenSocket(
- NULL,
-
(testOptions->multiple ?
-
mrange_next(listenc2sport) : listenc2sport), conn_options, 0)
+ c2ssrv_addr = CreateListenSocket(
+ NULL,
+ (testOptions->multiple ?
+ mrange_next(listenc2sport,
sizeof(listenc2sport)) : listenc2sport),
+ conn_options, 0)
;
if (strcmp(listenc2sport, "0") == 0) {
log_println(0, "WARNING: ephemeral port number was
bound");
@@ -145,10 +145,10 @@
0,
"Server (C2S throughput test):
CreateListenSocket failed: %s",
strerror(errno));
- sprintf(
- buff,
- "Server (C2S throughput test):
CreateListenSocket failed: %s",
- strerror(errno));
+ snprintf(buff,
+ sizeof(buff),
+ "Server (C2S throughput test): CreateListenSocket
failed: %s",
+ strerror(errno));
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return -1;
}
@@ -169,11 +169,10 @@
1,
"Sending 'GO' signal, to tell client %d to head
for the next test",
testOptions->child0);
- sprintf(buff, "%d", testOptions->c2ssockport);
+ snprintf(buff, sizeof(buff), "%d", testOptions->c2ssockport);

// send TEST_PREPARE message with ephemeral port detail, indicating start of tests
- if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff,
strlen(buff)))
- < 0)
+ if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff))) < 0)
return msgretvalue;

// Wait on listening socket and read data once ready.
@@ -352,10 +351,10 @@
stop_snap_worker(&workerThreadId, options->snaplog,
&snapArgs);

// send the server calculated value of C->S throughput as result to client
- sprintf(buff, "%6.0f kbps outbound for child %d", *c2sspd,
+ snprintf(buff, sizeof(buff), "%6.0f kbps outbound for child
%d", *c2sspd,
testOptions->child0);
log_println(1, "%s", buff);
- sprintf(buff, "%0.0f", *c2sspd);
+ snprintf(buff, sizeof(buff), "%0.0f", *c2sspd);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));

// get receiver side Web100 stats and write them to the log file. close sockets
@@ -386,16 +385,15 @@
continue;
if (((msgretvalue == -1) && (errno != EINTR))
|| (msgretvalue == 0)) {
- log_println(
- 4,
- "Failed to read pkt-pair
data from C2S flow, retcode=%d, reason=%d",
- msgretvalue, errno);
- sprintf(
- spds[(*spd_index)++],
- " -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- sprintf(
- spds[(*spd_index)++],
- " -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 0.0 0 0 0 0 0 -1");
+ log_println(4,
+ "Failed to read pkt-pair data from
C2S flow, retcode=%d, reason=%d",
+ msgretvalue, errno);
+ snprintf(spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0.0 0 0 0 0 0 -1");
+ snprintf(spds[(*spd_index)++],
+ sizeof(spds[*spd_index]),
+ " -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0.0 0 0 0 0 0 -1");
break;
}
/* There is something to read, so get it from the pktpair child. If an interrupt occurs,
@@ -403,10 +401,11 @@
* RAC 2/8/10
*/
if (msgretvalue > 0) {
- if ((msgretvalue = read(mon_pipe1[0],
spds[*spd_index], 128))
+ if ((msgretvalue = read(mon_pipe1[0], spds[*spd_index], sizeof(spds[*spd_index])))
< 0)
- sprintf(
+ snprintf(

spds[*spd_index],
+
sizeof(spds[*spd_index]),
" -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
log_println(1, "%d bytes read '%s' from
C2S monitor pipe",
msgretvalue,
spds[*spd_index]);
=======================================
--- /trunk/src/test_meta_clt.c Mon Oct 29 10:56:28 2012
+++ /trunk/src/test_meta_clt.c Mon Nov 5 10:30:55 2012
@@ -82,7 +82,7 @@
printf("sending meta information to server . . . . . ");
fflush(stdout);

- sprintf(buff, "%s:%s", META_CLIENT_APPLICATION, "cli");
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_APPLICATION,
"cli");
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
// send client os name details
if ((fp = fopen("/proc/sys/kernel/ostype", "r")) == NULL) {
@@ -90,12 +90,12 @@
} else {
fscanf(fp, "%s", tmpBuff);
fclose(fp);
- sprintf(buff, "%s:%s", META_CLIENT_OS, tmpBuff);
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_OS,
tmpBuff);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
}

// send client browser name
- sprintf(buff, "%s:%s", META_BROWSER_OS, "- (web100clt)");
+ snprintf(buff, sizeof(buff), "%s:%s", META_BROWSER_OS, "-
(web100clt)");
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

// send client kernel version
@@ -104,12 +104,12 @@
} else {
fscanf(fp, "%s", tmpBuff);
fclose(fp);
- sprintf(buff, "%s:%s", META_CLIENT_KERNEL_VERSION,
tmpBuff);
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_KERNEL_VERSION, tmpBuff);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));
}

// send NDT client version
- sprintf(buff, "%s:%s", META_CLIENT_VERSION, VERSION);
+ snprintf(buff, sizeof(buff), "%s:%s", META_CLIENT_VERSION,
VERSION);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

// Client can send any number of such meta data in a TEST_MSG
=======================================
--- /trunk/src/test_meta_srv.c Mon Oct 29 10:56:28 2012
+++ /trunk/src/test_meta_srv.c Mon Nov 5 10:30:55 2012
@@ -42,8 +42,8 @@
int conn_options) {
int j;
int msgLen, msgType;
- char buff[BUFFSIZE + 1];struct
-metaentry *new_entry = NULL;
+ char buff[BUFFSIZE + 1];
+ struct metaentry *new_entry = NULL;
char* value;

// protocol validation logs
@@ -77,21 +77,21 @@
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
// message reading error
log_println(0, "Protocol error!");
- sprintf(buff, "Server (META test): Invalid meta
data received");
+ snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
return 1;
}
if (check_msg_type("META test", TEST_MSG, msgType,
buff, msgLen)) {
// expected a TEST_MSG only
log_println(0, "Fault, unexpected message
received!");
- sprintf(buff, "Server (META test): Invalid meta
data received");
+ snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
return 2;
}
if (msgLen < 0) {
// meta data should be present at this stage
log_println(0, "Improper message");
- sprintf(buff, "Server (META test): Invalid meta
data received");
+ snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
return 3;
}
@@ -106,7 +106,7 @@
value = index(buff, ':');
if (value == NULL) { // key-value separates by ":"
log_println(0, "Improper message");
- sprintf(buff, "Server (META test): Invalid meta
data received");
+ snprintf(buff, sizeof(buff), "Server (META test): Invalid meta data received");
send_msg(ctlsockfd, MSG_ERROR, buff,
strlen(buff));
return 4;
}
=======================================
--- /trunk/src/test_mid_clt.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/test_mid_clt.c Mon Nov 5 10:30:55 2012
@@ -164,9 +164,10 @@

strlcat(testresult_str, buff, MIDBOX_TEST_RES_SIZE);

- memset(buff, 0, 128); // this should work since the throughput results from the server should
- // ...fit well
within 128 chars
- sprintf(buff, "%0.0f", spdin);
+ memset(buff, 0, sizeof(buff));
+ // this should work since the throughput results from the
server should
+ // ...fit well
within BUFFSIZE
+ snprintf(buff, sizeof(buff), "%0.0f", spdin);
log_println(4, "CWND limited speed = %0.2f kbps", spdin);

// client now sends throughput it calculated above to server, as a TEST_MSG
=======================================
--- /trunk/src/test_mid_srv.c Wed Aug 1 12:29:37 2012
+++ /trunk/src/test_mid_srv.c Mon Nov 5 10:30:55 2012
@@ -61,7 +61,7 @@
/* socklen_t optlen, clilen; */
socklen_t clilen;
char buff[BUFFSIZE + 1]; // buf used for message payload
-I2Addr midsrv_addr = NULL; // server address
+ I2Addr midsrv_addr = NULL; // server address
char listenmidport[10]; // listener socket for middlebox tests
int msgType;
int msgLen;
@@ -98,9 +98,9 @@
strlcpy(listenmidport, PORT3, sizeof(listenmidport));

if (options->midsockport) {
- sprintf(listenmidport, "%d", options->midsockport);
+ snprintf(listenmidport, sizeof(listenmidport), "%d", options->midsockport);
} else if (options->mainport) {
- sprintf(listenmidport, "%d", options->mainport + 2);
+ snprintf(listenmidport, sizeof(listenmidport), "%d", options->mainport + 2);
}

if (options->multiple) {
@@ -124,7 +124,7 @@
CreateListenSocket(
NULL,
(options->multiple ?
-
mrange_next(listenmidport) : listenmidport), conn_options, 0)
+ mrange_next(listenmidport, sizeof(listenmidport)) : listenmidport), conn_options, 0)
;
if (midsrv_addr == NULL) {
/*
@@ -146,7 +146,7 @@
log_println(0,
"Server (Middlebox test):
CreateListenSocket failed: %s",
strerror(errno));
- sprintf(buff,
+ snprintf(buff, sizeof(buff),
"Server (Middlebox test):
CreateListenSocket failed: %s",
strerror(errno));
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
@@ -159,7 +159,7 @@
log_println(1, " -- port: %d", options->midsockport);

// send this port number to client
- sprintf(buff, "%d", options->midsockport);
+ snprintf(buff, sizeof(buff), "%d", options->midsockport);
if ((msgretvalue = send_msg(ctlsockfd, TEST_PREPARE, buff,
strlen(buff)))
< 0)
return msgretvalue;
@@ -211,10 +211,10 @@
if ((midsfd == -1) && (errno == EINTR)) // socket interrupted, wait some more
goto midfd;

- sprintf(
- tmpstr,
- "------- middlebox connection setup
returned because (%d)",
- errno);
+ snprintf(tmpstr,
+ sizeof(tmpstr),
+ "------- middlebox connection setup returned
because (%d)",
+ errno);
if (get_debuglvl() > 1)
perror(tmpstr);
if (midsfd < 0)
@@ -240,7 +240,7 @@
}

// Perform S->C throughput test. Obtained results in "buff"
- web100_middlebox(midsfd, agent, conn, buff);
+ web100_middlebox(midsfd, agent, conn, buff, sizeof(buff));

// Transmit results in the form of a TEST_MSG message
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
@@ -250,23 +250,26 @@
msgLen = sizeof(buff);
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
log_println(0, "Protocol error!");
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (Middlebox test): Invalid CWND
limited throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return 1;
}
if (check_msg_type("Middlebox test", TEST_MSG, msgType, buff, msgLen)) { // only TEST_MSG type valid
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (Middlebox test): Invalid CWND
limited throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return 2;
}
if (msgLen <= 0) { // received message's length has to be a
valid one
log_println(0, "Improper message");
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (Middlebox test): Invalid CWND
limited throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return 3;
=======================================
--- /trunk/src/test_s2c_clt.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/test_s2c_clt.c Mon Nov 5 10:30:55 2012
@@ -214,7 +214,7 @@
I2AddrFree(sec_addr);

// send TEST_MSG to server with the client-calculated
throughput
- sprintf(buff, "%0.0f", spdin);
+ snprintf(buff, sizeof(buff), "%0.0f", spdin);
send_msg(ctlSocket, TEST_MSG, buff, strlen(buff));

// client now expected to receive web100 variables collected
by server
=======================================
--- /trunk/src/test_s2c_srv.c Tue Sep 25 06:49:57 2012
+++ /trunk/src/test_s2c_srv.c Mon Nov 5 10:30:55 2012
@@ -142,9 +142,9 @@
strlcpy(listens2cport, PORT4, sizeof(listens2cport));

if (testOptions->s2csockport) {
- sprintf(listens2cport, "%d",
testOptions->s2csockport);
+ snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->s2csockport);
} else if (testOptions->mainport) {
- sprintf(listens2cport, "%d", testOptions->mainport +
2);
+ snprintf(listens2cport, sizeof(listens2cport), "%d", testOptions->mainport + 2);
}

if (testOptions->multiple) {
@@ -153,12 +153,11 @@

// attempt to bind to a new port and obtain address structure with details of listening port
while (s2csrv_addr == NULL) {
- s2csrv_addr =
- CreateListenSocket(
- NULL,
+ s2csrv_addr = CreateListenSocket(NULL,

(testOptions->multiple ?
-
mrange_next(listens2cport) : listens2cport), conn_options, 0)
- ;
+
mrange_next(listens2cport, sizeof(listens2cport)) :
+
listens2cport),
+ conn_options, 0);
if (s2csrv_addr == NULL) {
/*
log_println(1, " Calling KillHung() because s2csrv_address failed to bind");
@@ -179,8 +178,9 @@
0,
"Server (S2C throughput test):
CreateListenSocket failed: %s",
strerror(errno));
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (S2C throughput test):
CreateListenSocket failed: %s",
strerror(errno));
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
@@ -196,7 +196,7 @@
pair.port2 = testOptions->s2csockport;

// Data received from speed-chk. Send TEST_PREPARE "GO" signal with port number
- sprintf(buff, "%d", testOptions->s2csockport);
+ snprintf(buff, sizeof(buff), "%d", testOptions->s2csockport);
j = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff));
if (j == -1) {
log_println(6, "S2C %d Error!, Test start message not
sent!",
@@ -438,7 +438,7 @@
memset(buff, 0, sizeof(buff));

// Send throughput, unsent byte count, total sent
byte count to client
- sprintf(buff, "%0.0f %d %0.0f", x2cspd, sndqueue,
bytes_written);
+ snprintf(buff, sizeof(buff), "%0.0f %d %0.0f", x2cspd, sndqueue, bytes_written);
if (send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff))
< 0)
log_println(6,
"S2C test - failed to send test
message to pid=%d",
@@ -482,11 +482,13 @@
4,
"Failed to read pkt-pair data from S2C flow, retcode=%d, reason=%d, EINTR=%d",
ret, errno,
EINTR);
- sprintf(
+ snprintf(

spds[(*spd_index)++],
+
sizeof(spds[*spd_index]),
" -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
- sprintf(
+ snprintf(

spds[(*spd_index)++],
+
sizeof(spds[*spd_index]),
" -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
break;
}
@@ -497,8 +499,9 @@
if (ret > 0) {
if ((ret = read(mon_pipe2[0],
spds[*spd_index], 128))
< 0)
- sprintf(
+ snprintf(

spds[*spd_index],
+
sizeof(spds[*spd_index]),
" -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 0.0 0 0 0 0 0 -1");
log_println(1,
"%d bytes read
'%s' from S2C monitor pipe", ret,
@@ -530,7 +533,7 @@
if (ret < 0) {
log_println(6, "S2C - No web100 data received for
pid=%d",
s2c_childpid);
- sprintf(buff, "No Data Collected: 000000");
+ snprintf(buff, sizeof(buff), "No Data Collected:
000000");
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
}

@@ -539,24 +542,27 @@
msgLen = sizeof(buff);
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) {
log_println(0, "Protocol error!");
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (S2C throughput test): Invalid S2C
throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return -1;
}
if (check_msg_type("S2C throughput test", TEST_MSG, msgType,
buff,
msgLen)) {
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (S2C throughput test): Invalid S2C
throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return -2;
}
if (msgLen <= 0) {
log_println(0, "Improper message");
- sprintf(
+ snprintf(
buff,
+ sizeof(buff),
"Server (S2C throughput test): Invalid S2C
throughput received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return -3;
@@ -587,4 +593,3 @@
}
return 0;
}
-
=======================================
--- /trunk/src/test_sfw_clt.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/test_sfw_clt.c Mon Nov 5 10:30:55 2012
@@ -244,7 +244,7 @@
log_println(1, " -- oport: %d", sfwsockport);

// Send a TEST_MSG to server with the client's port number
- sprintf(buff, "%d", sfwsockport);
+ snprintf(buff, sizeof(buff), "%d", sfwsockport);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));

// The server responds to the TEST_MSG messages with a TEST_START message.
=======================================
--- /trunk/src/test_sfw_srv.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/test_sfw_srv.c Mon Nov 5 10:30:55 2012
@@ -156,7 +156,7 @@
sfwsrv_addr = CreateListenSocket(NULL, "0", conn_options, 0);
if (sfwsrv_addr == NULL) {
log_println(0, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
- sprintf(buff, "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): CreateListenSocket failed: %s", strerror(errno));
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return -1;
}
@@ -195,7 +195,7 @@
}
else {
log_println(0, "Simple firewall test: Cannot find
connection");
- sprintf(buff, "Server (Simple firewall test): Cannot find
connection");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Cannot find connection");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return -1;
@@ -204,7 +204,7 @@

// try sending TEST_PREPARE msg with ephemeral port number to
client.
// If unable to, return
- sprintf(buff, "%d %d", sfwsockport, testTime);
+ snprintf(buff, sizeof(buff), "%d %d", sfwsockport, testTime);
if ((rc = send_msg(ctlsockfd, TEST_PREPARE, buff, strlen(buff)))
< 0)
return (rc);

@@ -213,21 +213,21 @@
msgLen = sizeof(buff);
if (recv_msg(ctlsockfd, &msgType, buff, &msgLen)) { // message reception error
log_println(0, "Protocol error!");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 1;
}
if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
log_println(0, "Fault, unexpected message received!");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 2;
}
if (msgLen <= 0) { // message reception has error
log_println(0, "Improper message");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 3;
@@ -238,7 +238,7 @@
buff[msgLen] = 0;
if (check_int(buff, &sfwport)) { // message data is not number, thus no port info received
log_println(0, "Invalid port number");
- sprintf(buff, "Server (Simple firewall test): Invalid port number received");
+ snprintf(buff, sizeof(buff), "Server (Simple firewall test): Invalid port number received");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
I2AddrFree(sfwsrv_addr);
return 4;
@@ -278,7 +278,7 @@
switch (select(sfwsockfd+1, &fds, NULL, NULL, &sel_tv)) {
case -1: // If SOCKET_ERROR - status of firewall
unknown
log_println(0, "Simple firewall test: select exited with
error");
- sprintf(buff, "%d", SFW_UNKNOWN);
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
finalize_sfw(ctlsockfd);
I2AddrFree(sfwsrv_addr);
@@ -286,7 +286,7 @@
return 1;
case 0:// Time expiration. SFW possible in C->S side
log_println(0, "Simple firewall test: no connection for %d seconds", testTime);
- sprintf(buff, "%d", SFW_POSSIBLE);
+ snprintf(buff, sizeof(buff), "%d", SFW_POSSIBLE);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
finalize_sfw(ctlsockfd);
I2AddrFree(sfwsrv_addr);
@@ -306,7 +306,7 @@
msgLen = sizeof(buff);
if (recv_msg(sockfd, &msgType, buff, &msgLen)) { // message received in error
log_println(0, "Simple firewall test: unrecognized
message");
- sprintf(buff, "%d", SFW_UNKNOWN);
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
close(sockfd);
finalize_sfw(ctlsockfd);
@@ -316,7 +316,7 @@
}
if (check_msg_type("Simple firewall test", TEST_MSG, msgType, buff, msgLen)) {
// unexpected message type received
- sprintf(buff, "%d", SFW_UNKNOWN);
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
close(sockfd);
finalize_sfw(ctlsockfd);
@@ -326,7 +326,7 @@
}
if (msgLen != SFW_TEST_DEFAULT_LEN) { // Expecting default 20 byte long "Simple firewall test" message
log_println(0, "Simple firewall test: Improper
message");
- sprintf(buff, "%d", SFW_UNKNOWN);
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
close(sockfd);
finalize_sfw(ctlsockfd);
@@ -338,7 +338,7 @@
if (strcmp(buff, "Simple firewall test") != 0) {
// Message was of correct length, but was not
expected content-wise
log_println(0, "Simple firewall test: Improper
message");
- sprintf(buff, "%d", SFW_UNKNOWN);
+ snprintf(buff, sizeof(buff), "%d", SFW_UNKNOWN);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
close(sockfd);
finalize_sfw(ctlsockfd);
@@ -348,7 +348,7 @@
}

// All messages were received correctly, hence no firewall
- sprintf(buff, "%d", SFW_NOFIREWALL);
+ snprintf(buff, sizeof(buff), "%d", SFW_NOFIREWALL);
send_msg(ctlsockfd, TEST_MSG, buff, strlen(buff));
close(sockfd);
finalize_sfw(ctlsockfd);
=======================================
--- /trunk/src/testoptions.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/testoptions.c Mon Nov 5 10:30:55 2012
@@ -154,15 +154,15 @@
* @param buff test suite description
* @param test_id id of the test
*/
-void add_test_to_suite(int* first, char * buff, int test_id) {
+void add_test_to_suite(int* first, char * buff, size_t buff_strlen, int test_id) {
char tmpbuff[16];
if (*first) {
*first = 0;
- sprintf(buff, "%d", test_id);
+ snprintf(buff, buff_strlen, "%d", test_id);
} else {
- memset(tmpbuff, 0, 16);
- sprintf(tmpbuff, " %d", test_id);
- strlcat(buff, tmpbuff, 16); //setting buffsize= 16 as is initialized in main()
+ memset(tmpbuff, 0, sizeof(tmpbuff));
+ snprintf(tmpbuff, sizeof(tmpbuff), " %d", test_id);
+ strlcat(buff, tmpbuff, buff_strlen);
}
}

@@ -181,7 +181,7 @@
*
*/

-int initialize_tests(int ctlsockfd, TestOptions* options, char * buff) {
+int initialize_tests(int ctlsockfd, TestOptions* options, char * buff, size_t buff_strlen) {
unsigned char useropt = 0;
int msgType;
int msgLen = 1;
@@ -194,17 +194,17 @@

// read the test suite request
if (recv_msg(ctlsockfd, &msgType, &useropt, &msgLen)) {
- sprintf(buff, "Invalid test suite request");
+ snprintf(buff, buff_strlen, "Invalid test suite request");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return (-1);
}
if (msgLen == -1) {
- sprintf(buff, "Client timeout");
+ snprintf(buff, buff_strlen, "Client timeout");
return (-4);
}
// Expecting a MSG_LOGIN with payload byte indicating tests to be run
if ((msgType != MSG_LOGIN) || (msgLen != 1)) {
- sprintf(buff, "Invalid test request");
+ snprintf(buff, buff_strlen, "Invalid test request");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return (-2);
}
@@ -220,25 +220,25 @@
& (TEST_MID | TEST_C2S | TEST_S2C | TEST_SFW |
TEST_STATUS
| TEST_META))) {
// message received does not indicate a valid test!
- sprintf(buff, "Invalid test suite request");
+ snprintf(buff, buff_strlen, "Invalid test suite request");
send_msg(ctlsockfd, MSG_ERROR, buff, strlen(buff));
return (-3);
}
// construct test suite request based on user options received
if (useropt & TEST_MID) {
- add_test_to_suite(&first, buff, TEST_MID);
+ add_test_to_suite(&first, buff, buff_strlen, TEST_MID);
}
if (useropt & TEST_SFW) {
- add_test_to_suite(&first, buff, TEST_SFW);
+ add_test_to_suite(&first, buff, buff_strlen, TEST_SFW);
}
if (useropt & TEST_C2S) {
- add_test_to_suite(&first, buff, TEST_C2S);
+ add_test_to_suite(&first, buff, buff_strlen, TEST_C2S);
}
if (useropt & TEST_S2C) {
- add_test_to_suite(&first, buff, TEST_S2C);
+ add_test_to_suite(&first, buff, buff_strlen, TEST_S2C);
}
if (useropt & TEST_META) {
- add_test_to_suite(&first, buff, TEST_META);
+ add_test_to_suite(&first, buff, buff_strlen, TEST_META);
}
return useropt;
}
=======================================
--- /trunk/src/testoptions.h Tue Oct 16 08:22:53 2012
+++ /trunk/src/testoptions.h Mon Nov 5 10:30:55 2012
@@ -56,7 +56,7 @@
int wait_sig;

int initialize_tests(int ctlsockfd, TestOptions* testOptions,
- char * test_suite);
+ char * test_suite, size_t test_suite_strlen);

void catch_s2c_alrm(int signo);

=======================================
--- /trunk/src/tr-mkmap.c Mon Apr 30 13:46:39 2012
+++ /trunk/src/tr-mkmap.c Mon Nov 5 10:30:55 2012
@@ -431,7 +431,7 @@
}
memset(&*new, 0, sizeof(struct tr_tree));
new->ip_addr = ip_addr;
- sprintf(new->hostname, "%u.%u.%u.%u",
+ snprintf(new->hostname, sizeof(new->hostname), "%u.%u.%u.%u",
(ip_addr & 0xff), ((ip_addr >> 8) & 0xff),
((ip_addr >> 16) & 0xff), (ip_addr >> 24));
/* resolve host name and store for later use */
@@ -513,7 +513,7 @@
memset(&*new, 0, sizeof(struct tr_tree6));
memcpy(new->ip_addr, ip_addr, sizeof(new->ip_addr));
inet_ntop(AF_INET6, new->ip_addr, nodename, nnlen);
- sprintf(new->hostname, "%s", nodename);
+ snprintf(new->hostname, sizeof(new->hostname), "%s",
nodename);
/* resolve host name and store for later use */

if (root == NULL) {
@@ -876,13 +876,13 @@
log_init(argv[0], debug);

if (DefaultTree == NULL) {
- sprintf(dtfn, "%s/%s", BASEDIR, DFLT_TREE);
+ snprintf(dtfn, sizeof(dtfn), "%s/%s", BASEDIR, DFLT_TREE);
DefaultTree = dtfn;
}

#ifdef AF_INET6
if (DefaultTree6 == NULL) {
- sprintf(dt6fn, "%s/%s", BASEDIR, DFLT_TREE6);
+ snprintf(dt6fn, sizeof(dt6fn), "%s/%s", BASEDIR, DFLT_TREE6);
DefaultTree6 = dt6fn;
}
#endif
=======================================
--- /trunk/src/tr-tree.h Mon Apr 30 13:46:39 2012
+++ /trunk/src/tr-tree.h Mon Nov 5 10:30:55 2012
@@ -9,10 +9,12 @@
#ifndef _JS_TR_TREE_H
#define _JS_TR_TREE_H

+#define HOSTNAME_STRLEN 256
+
struct tr_tree {
uint32_t ip_addr; /* IP addr of current node */
int branches;
- char hostname[256]; /* Hostname placeholder */
+ char hostname[HOSTNAME_STRLEN]; /* Hostname placeholder */
struct tr_tree *branch[25]; /* pointer to child */
struct tr_tree *left; /* pointer to child */
struct tr_tree *right; /* pointer to child */
@@ -28,7 +30,7 @@
struct tr_tree6 {
uint32_t ip_addr[4]; /* IP addr of the current node */
int branches;
- char hostname[256]; /* Hostname placeholder */
+ char hostname[HOSTNAME_STRLEN]; /* Hostname placeholder */
struct tr_tree6 *branch[25]; /* pointer to child */
struct tr_tree6 *left; /* pointer to child */
struct tr_tree6 *right; /* pointer to child */
=======================================
--- /trunk/src/viewtrace.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/viewtrace.c Mon Nov 5 10:30:55 2012
@@ -229,7 +229,7 @@
cur->totalspd / cur->totalcount);

if (cur->totalcount > 0) {
- sprintf(buff, "%d %d %d %d %d %d %d %d %d %d %d %d %0.2f",
+ snprintf(buff, sizeof(buff), "%d %d %d %d %d %d %d %d %d %d %d %d
%0.2f",
cur->links[0], cur->links[1], cur->links[2],
cur->links[3],
cur->links[4], cur->links[5], cur->links[6],
cur->links[7],
cur->links[8], cur->links[9], cur->links[10],
cur->links[11],
=======================================
--- /trunk/src/web100-admin.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/web100-admin.c Mon Nov 5 10:30:55 2012
@@ -194,51 +194,51 @@
// print details about bottleneck link's speed
switch (c2s_linkspeed_data) {
case DATA_RATE_INSUFFICIENT_DATA:
- sprintf(btlneck, "Insufficent Data");
+ snprintf(btlneck, sizeof(btlneck), "Insufficent Data");
break;
case DATA_RATE_SYSTEM_FAULT:
- sprintf(btlneck, "System Fault");
+ snprintf(btlneck, sizeof(btlneck), "System Fault");
break;
case DATA_RATE_RTT:
- sprintf(btlneck, "Round Trip Time");
+ snprintf(btlneck, sizeof(btlneck), "Round Trip Time");
break;
case DATA_RATE_DIAL_UP:
- sprintf(btlneck, "Dial-up modem");
+ snprintf(btlneck, sizeof(btlneck), "Dial-up modem");
break;
case DATA_RATE_T1:
if (((float) c2sspd / (float) s2cspd > .8)
&& ((float) c2sspd / (float) s2cspd < 1.2) &&
(c2sspd > 1000))
- sprintf(btlneck, "T1 subnet");
+ snprintf(btlneck, sizeof(btlneck), "T1 subnet");
else {
if (s2c_linkspeed_ack == 3)
- sprintf(btlneck, "Cable Modem");
+ snprintf(btlneck, sizeof(btlneck), "Cable
Modem");
else
- sprintf(btlneck, "DSL");
+ snprintf(btlneck, sizeof(btlneck), "DSL");
}
break;
case DATA_RATE_ETHERNET:
- sprintf(btlneck, "Ethernet");
+ snprintf(btlneck, sizeof(btlneck), "Ethernet");
break;
case DATA_RATE_T3:
- sprintf(btlneck, "T3/DS-3");
+ snprintf(btlneck, sizeof(btlneck), "T3/DS-3");
break;
case DATA_RATE_FAST_ETHERNET:
- sprintf(btlneck, "FastEthernet");
+ snprintf(btlneck, sizeof(btlneck), "FastEthernet");
break;
case DATA_RATE_OC_12:
- sprintf(btlneck, "OC-12");
+ snprintf(btlneck, sizeof(btlneck), "OC-12");
break;
case DATA_RATE_GIGABIT_ETHERNET:
- sprintf(btlneck, "Gigabit Ethernet");
+ snprintf(btlneck, sizeof(btlneck), "Gigabit Ethernet");
break;
case DATA_RATE_OC_48:
- sprintf(btlneck, "OC-48");
+ snprintf(btlneck, sizeof(btlneck), "OC-48");
break;
case DATA_RATE_10G_ETHERNET:
- sprintf(btlneck, "10 Gigabit Enet");
+ snprintf(btlneck, sizeof(btlneck), "10 Gigabit Enet");
break;
case DATA_RATE_RETRANSMISSIONS:
- sprintf(btlneck, "Retransmissions");
+ snprintf(btlneck, sizeof(btlneck), "Retransmissions");
}

/* Calculate some values */
@@ -536,7 +536,7 @@
* file. For now, use the system command to append the text to the just created file.
*/
fclose(fp);
- sprintf(tmpstr, "/bin/cat %s/admin_description.html >> %s", BASEDIR,
+ snprintf(tmpstr, sizeof(tmpstr), "/bin/cat %s/admin_description.html
%s", BASEDIR,
AdminFileName);
system(tmpstr);

@@ -553,8 +553,8 @@
lock.l_type = F_WRLCK;
i = fcntl(fileno(fp), F_SETLKW, lock);
log_println(1, "successfully locked '/tmp/view.string' for updating");
- sprintf(
- view_string,
+ snprintf(
+ view_string, sizeof(view_string),
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s",
maxc2sspd, minc2sspd, maxs2cspd, mins2cspd, totalcnt,
totmismatch,
totbad_cable, count[0], count[1], count[2], count[3],
count[4],
=======================================
--- /trunk/src/web100-pcap.c Fri Oct 26 07:31:56 2012
+++ /trunk/src/web100-pcap.c Mon Nov 5 10:30:55 2012
@@ -402,7 +402,8 @@
}

// make speed bin available to other processes
- sprintf(buff,
+ snprintf(buff,
+ sizeof(buff),
" %d %d %d %d %d %d %d %d %d %d %d %d %0.2f %d %d %d %d
%d %d",
cur->links[0], cur->links[1], cur->links[2],
cur->links[3],
cur->links[4], cur->links[5], cur->links[6],
cur->links[7],
@@ -967,8 +968,8 @@

memset(namebuf, 0, 200);
I2AddrNodeName(sockAddr, namebuf, &nameBufLen);
- memset(cmdbuf, 0, 256);
- sprintf(cmdbuf, "host %s and port %d", namebuf, I2AddrPort(sockAddr));
+ memset(cmdbuf, 0, sizeof(cmdbuf));
+ snprintf(cmdbuf, sizeof(cmdbuf), "host %s and port %d", namebuf, I2AddrPort(sockAddr));

log_println(1, "installing pkt filter for '%s'", cmdbuf);
log_println(1, "Initial pkt src data = %p", fwd.saddr);
@@ -985,7 +986,7 @@

if (dumptrace == 1) {
// Create log file
- sprintf(dir, "%s_%s:%d.%s_ndttrace",
+ snprintf(dir, sizeof(dir), "%s_%s:%d.%s_ndttrace",
get_ISOtime(isoTime, sizeof(isoTime)),
namebuf,
I2AddrPort(sockAddr), direction);
create_named_logdir(logdir, sizeof(logdir), dir, 0);
=======================================
--- /trunk/src/web100-util.c Tue Oct 16 08:22:53 2012
+++ /trunk/src/web100-util.c Mon Nov 5 10:30:55 2012
@@ -74,7 +74,7 @@
*
*/
void web100_middlebox(int sock, web100_agent* agent, web100_connection* cn,
- char *results) {
+ char *results, size_t results_strlen) {

web100_var* var;
web100_group* group;
@@ -107,7 +107,7 @@
// copy address into tmpstr String
I2AddrNodeName(addr, tmpstr, &tmpstrlen);
// now copy tmpstr containing address into "line"
- sprintf(line, "%s;", tmpstr);
+ snprintf(line, sizeof(line), "%s;", tmpstr);
memset(tmpstr, 0, 200);
// service name into tmpstr
I2AddrServName(addr, tmpstr, &tmpstrlen);
@@ -117,7 +117,7 @@
// terminate the IP address string
meta.server_ip[(strlen(line) - 1)] = 0;
// Add this address to results
- strlcat(results, line, (BUFFSIZE + 1)); // using a "known" hardcoded value for size of results
+ strlcat(results, line, results_strlen);
I2AddrFree(addr); // free memory

// Now perform the above set of functions for client address/service
name
@@ -126,10 +126,10 @@
addr = I2AddrBySockFD(get_errhandle(), sock, False);
memset(tmpstr, 0, 200);
I2AddrNodeName(addr, tmpstr, &tmpstrlen);
- sprintf(line, "%s;", tmpstr);
+ snprintf(line, sizeof(line), "%s;", tmpstr);
I2AddrServName(addr, tmpstr, &tmpstrlen);
log_print(3, "Client: %s%s ", line, tmpstr);
- strlcat(results, line, (BUFFSIZE + 1));
+ strlcat(results, line, results_strlen);
I2AddrFree(addr);

// get web100 values for the middlebox test result group
@@ -144,13 +144,13 @@
if (strcmp(vars[i], "CurMSS") == 0)
currentMSSval = atoi(

web100_value_to_text(web100_get_var_type(var), buff));
- sprintf(line, "%s;",
+ snprintf(line, sizeof(line), "%s;",

web100_value_to_text(web100_get_var_type(var), buff));
if (strcmp(line, "4294967295;") == 0)
- sprintf(line, "%d;", -1);
+ snprintf(line, sizeof(line), "%d;", -1);

//strlcat(results, line, sizeof(results));
- strlcat(results, line, (BUFFSIZE + 1));
+ strlcat(results, line, results_strlen);
log_print(3, "%s", line);
}
log_println(3, "");
@@ -263,7 +263,7 @@
// get values for group, var of IP Address of the Remote host's side of connection
web100_agent_find_var_and_group(agent, "RemAddress", &group, &var);
web100_raw_read(var, cn, buf);
- sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var),
buf));
+ snprintf(line, sizeof(line), "%s;", web100_value_to_text(web100_get_var_type(var), buf));
// write remote address to log file
if (fp)
fprintf(fp, "%s", line);
@@ -294,7 +294,7 @@
continue;
}
if (ok == 1) {
- sprintf(web_vars[i].value, "%s",
+ snprintf(web_vars[i].value, sizeof(web_vars[i].value),
"%s",

web100_value_to_text(web100_get_var_type(var), buf));
if (fp)
fprintf(fp, "%d;", (int32_t)
atoi(web_vars[i].value));
@@ -360,9 +360,9 @@
}

// assign values and transmit message with all web100 variables to socket receiver end
- sprintf(web_vars[i].value, "%s",
+ snprintf(web_vars[i].value, sizeof(web_vars[i].value), "%s",

web100_value_to_text(web100_get_var_type(var), buf));
- sprintf(line, "%s: %d\n", web_vars[i].name,
atoi(web_vars[i].value));
+ snprintf(line, sizeof(line), "%s: %d\n", web_vars[i].name, atoi(web_vars[i].value));
send_msg(ctlsock, TEST_MSG, line, strlen(line));
log_print(9, "%s", line);
}
=======================================
--- /trunk/src/web100srv.c Fri Oct 26 07:36:41 2012
+++ /trunk/src/web100srv.c Mon Nov 5 10:30:55 2012
@@ -639,31 +639,31 @@
}

else if (strncasecmp(key, "variable_file", 6) == 0) {
- sprintf(wvfn, "%s", val);
+ snprintf(wvfn, sizeof(wvfn), "%s", val);
VarFileName = wvfn;
continue;
}

else if (strncasecmp(key, "log_file", 3) == 0) {
- sprintf(lgfn, "%s", val);
+ snprintf(lgfn, sizeof(lgfn), "%s", val);
set_logfile(lgfn);
- sprintf(lgfn, "%s", val);
+ snprintf(lgfn, sizeof(lgfn), "%s", val);
continue;
} else if (strncasecmp(key, "protolog_dir", 12) == 0) {
- sprintf(lgfn, "%s", val);
+ snprintf(lgfn, sizeof(lgfn), "%s", val);
set_protologdir(lgfn);
continue;
} else if (strncasecmp(key, "enableprotolog", 11) == 0) {
enableprotocollogging();
continue;
} else if (strncasecmp(key, "admin_file", 10) == 0) {
- sprintf(apfn, "%s", val);
+ snprintf(apfn, sizeof(apfn), "%s", val);
AdminFileName = apfn;
continue;
}

else if (strncasecmp(key, "logfacility", 11) == 0) {
- sprintf(slfa, "%s", val);
+ snprintf(slfa, sizeof(slfa), "%s", val);
SysLogFacility = slfa;
continue;
}
@@ -835,7 +835,7 @@
pre_ptr = tmp_ptr;
tmp_ptr = tmp_ptr->next;
}
- sprintf(tmpstr, "9990");
+ snprintf(tmpstr, sizeof(tmpstr), "9990");
i = 0;
while (tmp_ptr != NULL) {
if (tmp_ptr->oldclient == 0) {
@@ -1049,7 +1049,7 @@
autotune = web100_autotune(ctlsockfd, agent, conn);

// client needs to be version compatible. Send current version
- sprintf(buff, "v%s", VERSION);
+ snprintf(buff, sizeof(buff), "v%s", VERSION);
send_msg(ctlsockfd, MSG_LOGIN, buff, strlen(buff));

// initiate test with MSG_LOGIN message.
@@ -1296,35 +1296,35 @@
congestion = POSSIBLE_CONGESTION;

// Send results and variable values to clients
- sprintf(buff, "c2sData: %d\nc2sAck: %d\ns2cData: %d\ns2cAck: %d\n", c2s_linkspeed_data,
+ snprintf(buff, sizeof(buff), "c2sData: %d\nc2sAck: %d\ns2cData: %d\ns2cAck: %d\n", c2s_linkspeed_data,
c2s_linkspeed_ack, s2c_linkspeed_data,
s2c_linkspeed_ack);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

- sprintf(
- buff,
+ snprintf(
+ buff,sizeof(buff),
"half_duplex: %d\nlink: %d\ncongestion: %d\nbad_cable: %d\nmismatch: %d\nspd: %0.2f\n",
half_duplex, link, congestion, bad_cable, mismatch,
realthruput);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

- sprintf(
- buff,
+ snprintf(
+ buff,sizeof(buff),
"bw: %0.2f\nloss: %0.9f\navgrtt: %0.2f\nwaitsec: %0.2f\ntimesec: %0.2f\norder: %0.4f\n",
bw_theortcl, packetloss_s2c, avgrtt, waitsec,
timesec, oo_order);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

- sprintf(
- buff,
+ snprintf(
+ buff,sizeof(buff),
"rwintime: %0.4f\nsendtime: %0.4f\ncwndtime: %0.4f\nrwin: %0.4f\nswin: %0.4f\n",
rwintime, sendtime, cwndtime, rwin, swin);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

- sprintf(
- buff,
+ snprintf(
+ buff,sizeof(buff),
"cwin: %0.4f\nrttsec: %0.6f\nSndbuf: %d\naspd: %0.5f\nCWND-Limited: %0.2f\n",
cwin, rttsec, Sndbuf, aspd, s2c2spd);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

- sprintf(buff, "minCWNDpeak: %d\nmaxCWNDpeak: %d\nCWNDpeaks: %d\n",
+ snprintf(buff, sizeof(buff), "minCWNDpeak: %d\nmaxCWNDpeak: %d\nCWNDpeaks: %d\n",
peaks.min, peaks.max, peaks.amount);
send_msg(ctlsockfd, MSG_RESULTS, buff, strlen(buff));

@@ -1333,45 +1333,45 @@

// Copy collected values into the meta data structures. This section
// seems most readable, easy to debug here.
- sprintf(meta.date, "%s", get_ISOtime(isoTime, sizeof(isoTime)));
+ snprintf(meta.date, sizeof(meta.date), "%s", get_ISOtime(isoTime, sizeof(isoTime)));

log_println(9, "meta.date=%s, meta.clientip =%s:%s:%d", meta.date,
meta.client_ip, rmt_host, strlen(rmt_host));
memcpy(meta.client_ip, rmt_host, strlen(rmt_host));
log_println(9, "2. meta.clientip =%s:%s:%d", meta.client_ip,
rmt_host);

- memset(tmpstr, 0, 255);
- sprintf(tmpstr, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,", (int)
s2c2spd,
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,", (int) s2c2spd,
(int) s2cspd, (int) c2sspd, Timeouts, SumRTT,
CountRTT, PktsRetrans,
FastRetran, DataPktsOut, AckPktsOut, CurrentMSS,
DupAcksIn,
AckPktsIn);
memcpy(meta.summary, tmpstr, strlen(tmpstr));
- memset(tmpstr, 0, 255);
- sprintf(tmpstr, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,",
MaxRwinRcvd,
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,", MaxRwinRcvd,
Sndbuf, MaxCwnd, SndLimTimeRwin, SndLimTimeCwnd,
SndLimTimeSender,
DataBytesOut, SndLimTransRwin, SndLimTransCwnd,
SndLimTransSender,
MaxSsthresh, CurrentRTO, CurrentRwinRcvd);

strlcat(meta.summary, tmpstr, sizeof(meta.summary));
- memset(tmpstr, 0, 255);
- sprintf(tmpstr, "%d,%d,%d,%d,%d", link, mismatch, bad_cable,
half_duplex,
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), "%d,%d,%d,%d,%d", link, mismatch, bad_cable, half_duplex,
congestion);

strlcat(meta.summary, tmpstr, sizeof(meta.summary));
- memset(tmpstr, 0, 255);
- sprintf(tmpstr, ",%d,%d,%d,%d,%d,%d,%d,%d,%d", c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data,
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), ",%d,%d,%d,%d,%d,%d,%d,%d,%d", c2s_linkspeed_data, c2s_linkspeed_ack, s2c_linkspeed_data,
s2c_linkspeed_ack, CongestionSignals, PktsOut, MinRTT, RcvWinScale, autotune);

strlcat(meta.summary, tmpstr, sizeof(meta.summary));
- memset(tmpstr, 0, 255);
- sprintf(tmpstr, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", CongAvoid,
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", CongAvoid,
CongestionOverCount, MaxRTT, OtherReductions,
CurTimeoutCount,
AbruptTimeouts, SendStall, SlowStart,
SubsequentTimeouts,
ThruBytesAcked);

strlcat(meta.summary, tmpstr, sizeof(meta.summary));
- memset(tmpstr, 0, 255);
- sprintf(tmpstr, ",%d,%d,%d", peaks.min, peaks.max, peaks.amount);
+ memset(tmpstr, 0, sizeof(tmpstr));
+ snprintf(tmpstr, sizeof(tmpstr), ",%d,%d,%d", peaks.min, peaks.max, peaks.amount);

strlcat(meta.summary, tmpstr, sizeof(meta.summary));
writeMeta(options.compress, cputime, options.snaplog, dumptrace);
@@ -1383,7 +1383,7 @@
"Unable to open log file '%s', continuing on
without logging",
get_logfile());
} else {
- sprintf(date, "%15.15s", ctime(&stime) + 4);
+ snprintf(date, sizeof(date), "%15.15s", ctime(&stime) + 4);
fprintf(fp, "%s,", date);
fprintf(fp, "%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,",
rmt_host,
(int) s2c2spd, (int) s2cspd, (int) c2sspd,
Timeouts, SumRTT,
@@ -1420,27 +1420,27 @@
SubsequentTimeouts, ThruBytesAcked, peaks.min,
peaks.max,
peaks.amount);
if (usesyslog == 1) {
- sprintf(
- logstr1,
+ snprintf(
+ logstr1, sizeof(logstr1),
"client_IP=%s,c2s_spd=%2.0f,s2c_spd=%2.0f,Timeouts=%d,SumRTT=%d,CountRTT=%d,PktsRetrans=%d,FastRetran=%d,DataPktsOut=%d,AckPktsOut=%d,CurrentMSS=%d,DupAcksIn=%d,AckPktsIn=%d,",
rmt_host, c2sspd, s2cspd, Timeouts, SumRTT,
CountRTT,
PktsRetrans, FastRetran, DataPktsOut,
AckPktsOut, CurrentMSS,
DupAcksIn, AckPktsIn);
- sprintf(
- logstr2,
+ snprintf(
+ logstr2, sizeof(logstr2),
"MaxRwinRcvd=%d,Sndbuf=%d,MaxCwnd=%d,SndLimTimeRwin=%d,SndLimTimeCwnd=%d,SndLimTimeSender=%d,DataBytesOut=%d,SndLimTransRwin=%d,SndLimTransCwnd=%d,SndLimTransSender=%d,MaxSsthresh=%d,CurrentRTO=%d,CurrentRwinRcvd=%d,",
MaxRwinRcvd, Sndbuf, MaxCwnd, SndLimTimeRwin,
SndLimTimeCwnd,
SndLimTimeSender, DataBytesOut,
SndLimTransRwin,
SndLimTransCwnd, SndLimTransSender,
MaxSsthresh, CurrentRTO,
CurrentRwinRcvd);
- strcat(logstr1, logstr2);
- sprintf(
- logstr2,
+ strlcat(logstr1, logstr2, sizeof(logstr1));
+ snprintf(
+ logstr2, sizeof(logstr2),
"link=%d,mismatch=%d,bad_cable=%d,half_duplex=%d,congestion=%d,c2s_linkspeed_data=%d,c2sack=%d,s2cdata=%d,s2cack=%d,CongestionSignals=%d,PktsOut=%d,MinRTT=%d,RcvWinScale=%d\n",
link, mismatch, bad_cable, half_duplex,
congestion, c2s_linkspeed_data,
c2s_linkspeed_ack, s2c_linkspeed_data, s2c_linkspeed_ack, CongestionSignals, PktsOut, MinRTT,
RcvWinScale);
- strcat(logstr1, logstr2);
+ strncat(logstr1, logstr2, sizeof(logstr1));
syslog(LOG_FACILITY | LOG_INFO, "%s", logstr1);
closelog();
log_println(4, "%s", logstr1);
@@ -1770,20 +1770,20 @@
}

if (VarFileName == NULL) {
- sprintf(wvfn, "%s/%s", BASEDIR, WEB100_FILE);
+ snprintf(wvfn, sizeof(wvfn), "%s/%s", BASEDIR, WEB100_FILE);
VarFileName = wvfn;
}

if (AdminFileName == NULL) {
- sprintf(apfn, "%s/%s", BASEDIR, ADMINFILE);
+ snprintf(apfn, sizeof(apfn), "%s/%s", BASEDIR, ADMINFILE);
AdminFileName = apfn;
}

if (DataDirName == NULL) {
- sprintf(logd, "%s/%s/", BASEDIR, LOGDIR);
+ snprintf(logd, sizeof(logd), "%s/%s/", BASEDIR, LOGDIR);
DataDirName = logd;
} else if (DataDirName[0] != '/') {
- sprintf(logd, "%s/%s/", BASEDIR, DataDirName);
+ snprintf(logd, sizeof(logd), "%s/%s/", BASEDIR, DataDirName);
DataDirName = logd;
}

@@ -2230,7 +2230,7 @@
}

log_println(6, "xxx, calling
initialize_tests()");
- t_opts = initialize_tests(ctlsockfd,
&testopt, test_suite);
+ t_opts = initialize_tests(ctlsockfd, &testopt, test_suite, sizeof(test_suite));

if (t_opts < 1) {
log_println(
@@ -2291,7 +2291,7 @@
0,
"Too many clients/mclients (%d) waiting to be served, Please try again later.",
chld_pid);
- sprintf(tmpstr, "9988"); // 9988 =
server_BUSY_OR_ERROR
+ snprintf(tmpstr, sizeof(tmpstr), "9988"); // 9988 = server_BUSY_OR_ERROR
send_msg(ctlsockfd, SRV_QUEUE, tmpstr,
strlen(tmpstr));
close(chld_pipe[0]);
close(chld_pipe[1]);
@@ -2306,7 +2306,7 @@
continue;
}

- t_opts = initialize_tests(ctlsockfd, &testopt,
test_suite);
+ t_opts = initialize_tests(ctlsockfd, &testopt, test_suite, sizeof(test_suite));
if (t_opts < 1) { // some error in initialization
routines
log_println(
3,
@@ -2429,7 +2429,7 @@
3,
"%d clients waiting, telling client (%d) testing will begin within %d minutes",
(waiting - 1), tmp_ptr->pid,
(waiting-1));
- sprintf(tmpstr, "%d",
(waiting-1));
+ snprintf(tmpstr, sizeof(tmpstr),
"%d", (waiting-1));
send_msg(tmp_ptr->ctlsockfd,
SRV_QUEUE, tmpstr, strlen(tmpstr));
continue;
}
@@ -2438,7 +2438,7 @@
int xx = waiting/max_clients;
log_println(3, "%d mclients waiting, tell client (%d) test will begin within %d minutes",
(waiting-max_clients),
mchild->pid, xx);
- sprintf(tmpstr, "%d", xx);
+ snprintf(tmpstr, sizeof(tmpstr),
"%d", xx);
send_msg(mchild->ctlsockfd,
SRV_QUEUE, tmpstr, strlen(tmpstr));
continue;
}
@@ -2471,7 +2471,7 @@
log_println(3, "%d clients waiting, updating client %d testing will begin within %d minutes",
(waiting-1),
tmp_ptr->pid, (waiting-j));

- sprintf(tmpstr, "%d",
(waiting-j));
+ snprintf(tmpstr, sizeof(tmpstr),
"%d", (waiting-j));
send_msg(tmp_ptr->ctlsockfd,
SRV_QUEUE, tmpstr, strlen(tmpstr));
tmp_ptr = tmp_ptr->next;
j--;
@@ -2524,7 +2524,7 @@
mchild->stime = time(0);
mchild->running = 1;
mclients++;
- sprintf(tmpstr, "go %d %s", t_opts,
mchild->tests);
+ snprintf(tmpstr, sizeof(tmpstr), "go %d
%s", t_opts, mchild->tests);
log_println(5, "sending 'GO' signal to
client msg='%s'", tmpstr);
send_msg(mchild->ctlsockfd, SRV_QUEUE, "0", 1); // test session starts now
for (i=0; i<5; i++) {
@@ -2551,7 +2551,7 @@
else {
head_ptr->stime = time(0);
head_ptr->running = 1;
- sprintf(tmpstr, "go %d %s", t_opts,
head_ptr->tests);
+ snprintf(tmpstr, sizeof(tmpstr), "go %d
%s", t_opts, head_ptr->tests);
log_println(5, "sending 'GO' signal to
client msg='%s'", tmpstr);
send_msg(head_ptr->ctlsockfd, SRV_QUEUE,
"0", 1);
for (i=0; i<5; i++) {
@@ -2634,7 +2634,8 @@
I2AddrFree(tmp_addr);
memset(cputimelog, 0, 256);
if (cputime) {
- sprintf(dir, "%s_%s:%d.cputime", get_ISOtime(isoTime, sizeof(isoTime)), name, testPort);
+ snprintf(dir, sizeof(dir),
"%s_%s:%d.cputime",
+
get_ISOtime(isoTime, sizeof(isoTime)), name, testPort);
log_println(8,
"CPUTIME:suffix=%s",dir);

create_named_logdir(cputimelog, sizeof(cputimelog),dir, 0);
memcpy(meta.CPU_time, dir,
strlen(dir));
=======================================
--- /trunk/src/web100srv.h Tue Oct 16 08:22:53 2012
+++ /trunk/src/web100srv.h Mon Nov 5 10:30:55 2012
@@ -202,7 +202,7 @@
void get_iflist(void);
int web100_init(char *VarFileName);
int web100_autotune(int sock, web100_agent* agent, web100_connection* cn);
-void web100_middlebox(int sock, web100_agent* agent, web100_connection* cn, char *results);
+void web100_middlebox(int sock, web100_agent* agent, web100_connection* cn, char *results, size_t results_strlen);
int web100_setbuff(int sock, web100_agent* agent, web100_connection* cn, int autotune);
void web100_get_data_recv(int sock, web100_agent* agent, web100_connection* cn, int count_vars);
int web100_get_data(web100_snapshot* snap, int ctlsock, web100_agent* agent, int count_vars);


  • [ndt-dev] [ndt] r788 committed - Replacing sprintf with snprintf, ndt, 11/05/2012

Archive powered by MHonArc 2.6.16.

Top of Page