Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r719 committed - Buffer overflow prevention:

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r719 committed - Buffer overflow prevention:


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r719 committed - Buffer overflow prevention:
  • Date: Fri, 14 Oct 2011 20:53:10 +0000

Revision: 719
Author:

Date: Fri Oct 14 13:52:19 2011
Log: Buffer overflow prevention:
http://code.google.com/p/ndt/source/detail?r=719

Modified:
/branches/kkumar_code_organize/src/logging.c
/branches/kkumar_code_organize/src/logging.h
/branches/kkumar_code_organize/src/mrange.c
/branches/kkumar_code_organize/src/ndt_odbc.c
/branches/kkumar_code_organize/src/test_mid_clt.c
/branches/kkumar_code_organize/src/test_s2c_clt.c
/branches/kkumar_code_organize/src/test_sfw_srv.c
/branches/kkumar_code_organize/src/testoptions.c
/branches/kkumar_code_organize/src/tr-mkmap.c
/branches/kkumar_code_organize/src/utils.c
/branches/kkumar_code_organize/src/web100-admin.c
/branches/kkumar_code_organize/src/web100-pcap.c
/branches/kkumar_code_organize/src/web100-util.c
/branches/kkumar_code_organize/src/web100clt.c
/branches/kkumar_code_organize/src/web100srv.c

=======================================
--- /branches/kkumar_code_organize/src/logging.c Thu Oct 13 10:32:49
2011
+++ /branches/kkumar_code_organize/src/logging.c Fri Oct 14 13:52:19
2011
@@ -23,6 +23,7 @@
//new addition after separating out ndtptests header, to include test types
#include "testoptions.h" // Used only for getCurrentTest(), which can probably be moved elsewhere
//#include "runningtest.h" // protocol validation
+#include "strlutils.h"


static int _debuglevel = 0;
@@ -256,7 +257,8 @@
}
sprintf(protologlocalarr, "%s/%s%s%s%s", ProtocolLogDirName, PROTOLOGPREFIX , client_ip,
PROTOLOGSUFFIX,"\0");
- strncpy(ProtocolLogFileName, protologlocalarr,
strnlen(protologlocalarr));
+ //strncpy(ProtocolLogFileName, protologlocalarr, strnlen(protologlocalarr));
+ strlcpy(ProtocolLogFileName, protologlocalarr, sizeof(ProtocolLogFileName));

//log_println (0, "***SET %s: %s;****\n", ProtocolLogFileName, ProtocolLogDirName);

@@ -419,7 +421,7 @@
log_println(0, "--Unable to open proto file while trying to record msg: %s \n", key, value);
}
else {
- fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key, value, get_ISOtime(isotime));
+ fprintf(fp, " event=\"%s\", name=\"%s\", time=\"%s\"\n", key, value, get_ISOtime(isotime,sizeof(isotime)));
printf("%s = \"%s\" \n", key, logmessage);
fclose(fp);
}
@@ -467,7 +469,7 @@
teststatusdesc, currenttestname);
}
else {
- sprintf(protomessage, " event=\"%s\", name=\"%s\", pid=\"%d\", time=\"%s\"\n",teststatusdesc, currenttestname, pid, get_ISOtime(isotime) );
+ sprintf(protomessage, " event=\"%s\", name=\"%s\", pid=\"%d\", time=\"%s\"\n",teststatusdesc, currenttestname, pid, get_ISOtime(isotime, sizeof(isotime)) );
printf("%s: <-- %d - %s - %s --> \n ", protomessage, pid, teststatusdesc, currenttestname );
fprintf(fp, "%s", protomessage);
fclose(fp);
@@ -519,7 +521,7 @@
}
else {
sprintf(protomessage, " event=\"%s\", name=\"%s\", test=\"%s\", pid=\"%d\", time=\"%s\"\n",procstatusdesc,
- currentprocname, currenttestname, pid,
get_ISOtime(isotime) );
+ currentprocname, currenttestname, pid, get_ISOtime(isotime, sizeof(isotime)) );
printf("%s: -- %d - %s - %s - %s -- \n ", protomessage, pid,currenttestname, procstatusdesc, currentprocname );
fprintf(fp, "%s", protomessage);
fclose(fp);
@@ -575,9 +577,9 @@
msgdirection, currenttestname, currentmsgtype, len, (char*)msg, processid, ctlSocket, get_ISOtime(isotime));
*/
fprintf(fp, " event=\"message\", direction=\"%s\", test=\"%s\", type=\"%s\", len=\"%d\", msg=\"%s\", pid=\"%d\", socket=\"%d\", time=\"%s\"\n",
- msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket,get_ISOtime(isotime));
+ msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket,get_ISOtime(isotime,sizeof(isotime)));
printf("direction = %s, test= %s, type=%s, len=%d, msg=%s, pid=%d, socket=%d, time=%s\n",
- msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket, get_ISOtime(isotime));
+ msgdirection, currenttestname, currentmsgtype, len, logmessage, processid, ctlSocket, get_ISOtime(isotime,sizeof(isotime)));
fclose(fp);
}
}
@@ -738,10 +740,11 @@
* Author: Rich Carlson - 5/6/09
* @param Pointer to the string indicating ISO time
* @param character string with ISO time string.
+ * #param
*/

char *
- get_ISOtime (char *isoTime)
+ get_ISOtime (char *isoTime, int isotimearrsize)
{

struct tm *result;
@@ -757,34 +760,40 @@
sprintf(tmpstr, "0%d", 1+result->tm_mon);
else
sprintf(tmpstr, "%d", 1+result->tm_mon);
-strncat(isoTime, tmpstr, 2);
+//strncat(isoTime, tmpstr, 2);
+strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_mday < 10)
sprintf(tmpstr, "0%d", result->tm_mday);
else
sprintf(tmpstr, "%d", result->tm_mday);
-strncat(isoTime, tmpstr, 2);
+//strncat(isoTime, tmpstr, 2);
+strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_hour < 10)
sprintf(tmpstr, "T0%d", result->tm_hour);
else
sprintf(tmpstr, "T%d", result->tm_hour);
-strncat(isoTime, tmpstr, 3);
+//strncat(isoTime, tmpstr, 3);
+strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_min < 10)
sprintf(tmpstr, ":0%d", result->tm_min);
else
sprintf(tmpstr, ":%d", result->tm_min);
-strncat(isoTime, tmpstr, 3);
+//strncat(isoTime, tmpstr, 3);
+strlcat(isoTime, tmpstr, isotimearrsize);

if (result->tm_sec < 10)
sprintf(tmpstr, ":0%d", result->tm_sec);
else
sprintf(tmpstr, ":%d", result->tm_sec);
-strncat(isoTime, tmpstr, 3);
+//strncat(isoTime, tmpstr, 3);
+strlcat(isoTime, tmpstr, isotimearrsize);

sprintf(tmpstr, ".%ldZ", get_utimestamp()*1000);
-strncat(isoTime, tmpstr, 11);
+//strncat(isoTime, tmpstr, 11);
+strlcat(isoTime, tmpstr, isotimearrsize);
return isoTime;
}

@@ -845,25 +854,31 @@
// The "primary" location for this log file is obtained as a command line option
// from the user, or is the default location of BASE_DIR+LOG_DIR of the NDT installation
//TODO : Move this into a new method??
- strncpy(tmpstr, DataDirName, strlen(DataDirName));
+ //strncpy(tmpstr, DataDirName, strlen(DataDirName));
+ strlcpy(tmpstr, DataDirName, sizeof(tmpstr));
// Open the directory or create one if not yet present
if ((dp = opendir(tmpstr)) == NULL && errno == ENOENT)
mkdir(tmpstr, 0755);
closedir(dp); // close opened directory
get_YYYY(dir); // get current year
- strncat(tmpstr, dir, 4);
+ //strncat(tmpstr, dir, 4);
+ strlcat(tmpstr, dir, sizeof(tmpstr));
if ((dp = opendir(tmpstr)) == NULL && errno == ENOENT)
mkdir(tmpstr, 0755); // create directory with year appended
closedir(dp); // close the opened directory
- strncat(tmpstr, "/", 1);
+ //strncat(tmpstr, "/", 1);
+ strlcat(tmpstr, "/", sizeof(tmpstr));
get_MM(dir); // get month info
- strncat(tmpstr, dir, 2); // append month info to the directory name
+ //strncat(tmpstr, dir, 2); // append month info to the directory name
+ strlcat(tmpstr, dir, sizeof(tmpstr)); // append month info to the directory name
if ((dp = opendir(tmpstr)) == NULL && errno == ENOENT)
mkdir(tmpstr, 0755);
closedir(dp);
- strncat(tmpstr, "/", 1);
+ //strncat(tmpstr, "/", 1);
+ strlcat(tmpstr, "/", sizeof(tmpstr));
get_DD(dir); // get date
- strncat(tmpstr, dir, 2); // append date info to directory name
+ //strncat(tmpstr, dir, 2); // append date info to directory name
+ strlcat(tmpstr, dir, sizeof(tmpstr)); // append date info to directory name
if ((dp = opendir(tmpstr)) == NULL && errno == ENOENT)
mkdir(tmpstr, 0755);
closedir(dp);
@@ -873,11 +888,17 @@

memcpy(tmp2str, tmpstr, tmpstrlen); // tmp2str now contains the dir name intended
// tmpstr will henceforth refer to the log file's name
- strncat(tmpstr, "/", 1);
- sprintf(dir, "%s_%s:%d.meta", get_ISOtime(isoTime), meta.client_ip,
+ //strncat(tmpstr, "/", 1);
+ strlcat(tmpstr, "/", sizeof(tmpstr));
+ // todo remove debug stmt
+ log_println(0, " ***meta.client_ip now: %s",
+ meta.client_ip);
+ sprintf(dir, "%s_%s:%d.meta", get_ISOtime(isoTime,sizeof(isoTime)), meta.client_ip,
meta.ctl_port); // now get ISO time, the client's
name and port
- strncat(tmpstr, dir, strlen(dir)); // append above details to log
filename
-
+ //strncat(tmpstr, dir, strlen(dir)); // append above details to log filename
+ strlcat(tmpstr, dir, sizeof(tmpstr)); // append above details to log filename
+ log_println(0, " ** meta.client_ip now: %s",
+ meta.client_ip); //todo remove debug
stmt

log_println(6, "Should compress snaplog and tcpdump files
compress=%d",
compress);
@@ -897,18 +918,20 @@
sprintf(filename, "%s/%s", tmp2str, meta.c2s_snaplog);
if (zlib_def(filename) != 0)
//log_println(5, "compression failed ");
- log_println(0, "compression failed for
file:%s", meta.c2s_snaplog);
+ log_println(0, "compression failed for file:%s: %s.", filename, tmp2str);
else
- strncat(meta.c2s_snaplog, ".gz", 3);
+ //strncat(meta.c2s_snaplog, ".gz", 3);
+ strlcat(meta.c2s_snaplog, ".gz",
sizeof(meta.c2s_snaplog));

// Try compressing S->C test snaplogs
memset(filename, 0, 256);
sprintf(filename, "%s/%s", tmp2str, meta.s2c_snaplog);
if (zlib_def(filename) != 0)
//log_println(5, "compression failed");
- log_println(0, "compression failed for file
:%s",meta.s2c_snaplog);
+ log_println(0, "compression failed for file
:%s",filename);
else
- strncat(meta.s2c_snaplog, ".gz", 3);
+ //strncat(meta.s2c_snaplog, ".gz", 3);
+ strlcat(meta.s2c_snaplog, ".gz",
sizeof(meta.s2c_snaplog));
}

// If tcpdump file writing is enabled, compress those
@@ -920,17 +943,23 @@
memset(filename, 0, 256);
sprintf(filename, "%s/%s", tmp2str,
meta.c2s_ndttrace);
if (zlib_def(filename) != 0)
- log_println(5, "compression failed");
+ //log_println(5, "compression failed");
+ //todo change level
+ log_println(0, "compression failed for tcpdump file %s =%s",filename, meta.c2s_ndttrace);
else
- strncat(meta.c2s_ndttrace, ".gz", 3);
+ //strncat(meta.c2s_ndttrace, ".gz", 3);
+ strlcat(meta.c2s_ndttrace, ".gz",
sizeof(meta.c2s_ndttrace));

// Try compressing S->C test tcpdumps
memset(filename, 0, 256);
sprintf(filename, "%s/%s", tmp2str,
meta.s2c_ndttrace);
if (zlib_def(filename) != 0)
- log_println(5, "compression failed");
+ //log_println(5, "compression failed");
+ //todo change level
+ log_println(0, "compression failed for tcpdump file %s =%s",filename, meta.s2c_ndttrace);
else
- strncat(meta.s2c_ndttrace, ".gz", 3);
+ //strncat(meta.s2c_ndttrace, ".gz", 3);
+ strlcat(meta.s2c_ndttrace, ".gz",
sizeof(meta.s2c_ndttrace));
}

// If writing "cputime" file is enabled, compress those log
files too
@@ -941,7 +970,8 @@
if (zlib_def(filename) != 0)
log_println(5, "compression failed");
else
- strncat(meta.CPU_time, ".gz", 3);
+ //strncat(meta.CPU_time, ".gz", 3);
+ strlcat(meta.CPU_time, ".gz",
sizeof(meta.CPU_time));
}
else
log_println(
@@ -1040,15 +1070,15 @@


/** Method to create directories for snap log files
-* @param namebufarg string containing ip address/name of client
-* @param socketaddrarg string containing socket address
-* @param direnamedestarg location to store final directory name
-* @param finalsuffix string constant suffix indicating C2S/S2c etc
+* @param namebufarg string containing ip address/name of client
+* @param socketaddrarg string containing socket address
+* @param direnamedestarg location to store final directory name
+* @param destnamearrsize Size of dest name string
+* @param finalsuffix string constant suffix indicating C2S/S2c etc
+* @param finalsuffixsize string constant suffix indicating C2S/S2c etc
*/
-//void createDir(char const* namebufarg, char const *socketaddrarg, char *dirnamedestarg,
-// char *finalsuffix) {
-void createDir(struct sockaddr *cliaddrarg, socklen_t clilenarg, char *dirnamedestarg,
- char *finalsuffix) {
+void create_client_logdir(struct sockaddr *cliaddrarg, socklen_t clilenarg, char *dirnamedestarg, int destnamearrsize,
+ char *finalsuffix, int finalsuffixsize) {
char namebuf[256];
size_t namebuflen = 255;
char dir[128];
@@ -1062,31 +1092,40 @@
socketaddrport = I2AddrPort(sockAddr);


- strncpy(dirnamedestarg, DataDirName, strlen(DataDirName));
+ //strncpy(dirnamedestarg, DataDirName, strlen(DataDirName));
+ strlcpy(dirnamedestarg, DataDirName, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
mkdir(dirnamedestarg, 0755);
closedir(dp);
get_YYYY(dir);
- strncat(dirnamedestarg, dir, 4);
+ //strncat(dirnamedestarg, dir, 4);
+ strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
mkdir(dirnamedestarg, 0755);
closedir(dp);
- strncat(dirnamedestarg, "/", 1);
+ //strncat(dirnamedestarg, "/", 1);
+ strlcat(dirnamedestarg, "/", destnamearrsize);
get_MM(dir);
- strncat(dirnamedestarg, dir, 2);
+ //strncat(dirnamedestarg, dir, 2);
+ strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
mkdir(dirnamedestarg, 0755);
closedir(dp);
- strncat(dirnamedestarg, "/", 1);
+ //strncat(dirnamedestarg, "/", 1);
+ strlcat(dirnamedestarg, "/", destnamearrsize);
get_DD(dir);
- strncat(dirnamedestarg, dir, 2);
+ //strncat(dirnamedestarg, dir, 2);
+ strlcat(dirnamedestarg, dir, destnamearrsize);
if ((dp = opendir(dirnamedestarg)) == NULL && errno == ENOENT)
mkdir(dirnamedestarg, 0755);
closedir(dp);
- strncat(dirnamedestarg, "/", 1);
- sprintf(dir, "%s_%s:%d.%s", get_ISOtime(isoTime), namebuf, socketaddrport, finalsuffix);
- strncpy(finalsuffix, dir, strlen(dir));
- strncat(dirnamedestarg, dir, strlen(dir));
+ //strncat(dirnamedestarg, "/", 1);
+ strlcat(dirnamedestarg, "/", destnamearrsize);
+ sprintf(dir, "%s_%s:%d.%s", get_ISOtime(isoTime, sizeof(isoTime)), namebuf, socketaddrport, finalsuffix);
+ //strncpy(finalsuffix, dir, strlen(dir));
+ strlcpy(finalsuffix, dir, finalsuffixsize);
+ //strncat(dirnamedestarg, dir, strlen(dir));
+ strlcat(dirnamedestarg, dir, destnamearrsize);

I2AddrFree(sockAddr);
}
=======================================
--- /branches/kkumar_code_organize/src/logging.h Sun Oct 9 17:00:18
2011
+++ /branches/kkumar_code_organize/src/logging.h Fri Oct 14 13:52:19
2011
@@ -34,7 +34,7 @@
void set_timestamp();
time_t get_timestamp();
long int get_utimestamp();
-char * get_ISOtime(char * isoTime);
+char * get_ISOtime(char * isoTime, int isoTimeArrSize);
void get_YYYY(char * year);
void get_MM(char * month);
void get_DD(char * day);
@@ -58,10 +58,10 @@
* meta data file created for every session
* */
struct metadata {
- char c2s_snaplog[64]; // C->S test Snaplog file name
- char c2s_ndttrace[64]; // C->S NDT trace file name
- char s2c_snaplog[64]; // S->C test Snaplog file name
- char s2c_ndttrace[64]; // S->C NDT trace file name
+ char c2s_snaplog[256]; // C->S test Snaplog file name, changed to 256 to avoid truncation
+ char c2s_ndttrace[256]; // C->S NDT trace file name, changed to 256 to avoid truncation
+ char s2c_snaplog[256]; // S->C test Snaplog file name, changed to 256 to avoid truncation
+ char s2c_ndttrace[256]; // S->C NDT trace file name, changed to 256 to avoid truncation
char CPU_time[64]; // CPU time file
char summary[256]; // Summary data
char date[32]; // Date and,
=======================================
--- /branches/kkumar_code_organize/src/mrange.c Fri Sep 23 13:50:35 2011
+++ /branches/kkumar_code_organize/src/mrange.c Fri Oct 14 13:52:19 2011
@@ -12,6 +12,7 @@

#include "utils.h"
#include "logging.h"
+#include "strlutils.h"

typedef struct range {
int min; /**< lower end of the range */
@@ -43,7 +44,8 @@
if (strlen(text) > 299) {
return 1;
}
- strcpy(tmp, text);
+ //strcpy(tmp, text);
+ strlcpy(tmp, text, sizeof(tmp));
// tokenize based on a "," character.
// An example of the string : 2003:3000,4000:5000
ptr = strtok(tmp, ",");
=======================================
--- /branches/kkumar_code_organize/src/ndt_odbc.c Fri Sep 16 08:39:32
2011
+++ /branches/kkumar_code_organize/src/ndt_odbc.c Fri Oct 14 13:52:19
2011
@@ -16,6 +16,7 @@

#include "ndt_odbc.h"
#include "logging.h"
+#include "strlutils.h"

#if defined(HAVE_ODBC) && defined(DATABASE_ENABLED) && defined(HAVE_SQL_H)
SQLHENV env;
@@ -158,13 +159,18 @@
memset(loginstring, 0, 1024);
snprintf(loginstring, 256, "DSN=%s;", dsn);
if (uid) {
- strcat(loginstring, "UID=");
+ /*strcat(loginstring, "UID=");
strncat(loginstring, uid, 256);
- strcat(loginstring, ";");
+ strcat(loginstring, ";");*/
+ strlcat(loginstring, "UID=", sizeof(loginstring));
+ strlcat(loginstring, uid, sizeof(loginstring));
+ strlcat(loginstring, ";", sizeof(loginstring));
}
if (pwd) {
- strcat(loginstring, "PWD=");
- strncat(loginstring, pwd, 256);
+ //strcat(loginstring, "PWD=");
+ strlcat(loginstring, "PWD=", sizeof(loginstring));
+ //strncat(loginstring, pwd, 256);
+ strlcat(loginstring, pwd, sizeof(loginstring));
}
ret = SQLDriverConnect(dbc, NULL, (unsigned char*) loginstring, SQL_NTS,
outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
@@ -209,7 +215,9 @@
buf, sizeof(buf), &indicator);
if (SQL_SUCCEEDED(ret)) {
// Handle null columns
- if (indicator == SQL_NULL_DATA) strcpy(buf, "NULL");
+ if (indicator == SQL_NULL_DATA)
+ //strcpy(buf, "NULL");
+ strlcpy(buf, "NULL", sizeof(buf));
if (strcmp(buf, "ndt_test_results") == 0) {
// the table exists - do nothing
SQLFreeStmt(stmt, SQL_CLOSE);
=======================================
--- /branches/kkumar_code_organize/src/test_mid_clt.c Tue Jun 30 09:17:48 2009
+++ /branches/kkumar_code_organize/src/test_mid_clt.c Fri Oct 14 13:52:19 2011
@@ -110,7 +110,8 @@
if (check_msg_type("Middlebox test results", TEST_MSG, msgType, buff, msgLen)) {
return 2;
}
- strncat(tmpstr2, buff, msgLen);
+ //strncat(tmpstr2, buff, msgLen);
+ strlcat(tmpstr2, buff, 512); //todo hardcoded size for now

memset(buff, 0, 128);
sprintf(buff, "%0.0f", spdin);
=======================================
--- /branches/kkumar_code_organize/src/test_s2c_clt.c Tue Jun 30 09:17:48 2009
+++ /branches/kkumar_code_organize/src/test_s2c_clt.c Fri Oct 14 13:52:19 2011
@@ -182,7 +182,8 @@
if (check_msg_type("S2C throughput test", TEST_MSG, msgType, buff, msgLen)) {
return 2;
}
- strncat(tmpstr, buff, msgLen);
+ //strncat(tmpstr, buff, msgLen);
+ strlcat(tmpstr, buff, 512); //todo hardcoded size of array for now
log_println(6, "tmpstr = '%s'", tmpstr);
}
log_println(1, " <------------------------->");
=======================================
--- /branches/kkumar_code_organize/src/test_sfw_srv.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/test_sfw_srv.c Fri Oct 14 13:52:19 2011
@@ -16,6 +16,7 @@
#include "utils.h"
#include "testoptions.h"
#include "runningtest.h"
+#include "strlutils.h"


static pthread_mutex_t mainmutex = PTHREAD_MUTEX_INITIALIZER;
@@ -184,7 +185,8 @@
web100_agent_find_var_and_group(agent, "RemAddress", &group, &var);
web100_raw_read(var, cn, buff);
memset(hostname, 0, 256);
- strncpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), 255);
+ //strncpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), 255);
+ strlcpy(hostname, web100_value_to_text(web100_get_var_type(var), buff), sizeof(hostname));

// Determine test time in seconds.
// test-time = max(round trip time, timeout) > 3 ? 3 : 1
=======================================
--- /branches/kkumar_code_organize/src/testoptions.c Thu Oct 13 10:32:49 2011
+++ /branches/kkumar_code_organize/src/testoptions.c Fri Oct 14 13:52:19 2011
@@ -18,6 +18,7 @@
#include "protocol.h"
#include "I2util/util.h"
#include "runningtest.h"
+#include "strlutils.h"

int mon_pipe1[2]; // used to store file descriptors of pipes created for ndttrace for C2S tests
int mon_pipe2[2]; // used to store file descriptors of pipes created for ndttrace data in S2c test
@@ -194,7 +195,8 @@
else {
memset(tmpbuff, 0, 16);
sprintf(tmpbuff, " %d", test_id);
- strcat(buff, tmpbuff);
+ //strcat(buff, tmpbuff);
+ strlcat(buff, tmpbuff, 16); //setting buffsize= 16 as is initialized in main()
}
}

@@ -275,9 +277,17 @@
return useropt;
}

-/* Method to write into snap worker */
-//start_snap_worker (&snapArgs, agent, options->snaplog, &workerLoop);
-
+/** Method to start snap worker thread that collects snap logs
+ * @param snaparg object
+ * @param web100_agent Agent
+ * @param snaplogenabled Is snap logging enabled?
+ * @param workerlooparg integer used to syncronize writing/reading from snaplog/web100 snapshot
+ * @param wrkrthreadidarg Thread Id of worker
+ * @param metafilevariablename Which variable of the meta file gets assigned the snaplog name (unused now)
+ * @param metafilename value of metafile name
+ * @param web100_connection connection pointer
+ * @param web100_group group web100_group pointer
+ */
void start_snap_worker(SnapArgs *snaparg, web100_agent *agentarg, char snaplogenabled, int *workerlooparg,
pthread_t *wrkrthreadidarg,
char *metafilevariablename, char *metafilename,
@@ -359,7 +369,8 @@
* */

void start_packet_trace (int socketfdarg, int socketfdarg2, pid_t *childpid, int *imonarg,
- struct sockaddr *cliaddrarg, socklen_t clilenarg, char* device, PortPair* pairarg, const char* testindicatorarg, int iscompressionenabled, char *copylocationarg) {
+ struct sockaddr *cliaddrarg, socklen_t clilenarg, char* device, PortPair* pairarg, const char* testindicatorarg,
+ int iscompressionenabled, char *copylocationarg) {

char tmpstr[256];
int i, readretval;
@@ -541,7 +552,8 @@

// determine port to be used. Compute based on options set earlier
// by reading from config file, or use default port3 (3003),
- strcpy(listenmidport, PORT3);
+ //strcpy(listenmidport, PORT3);
+ strlcpy(listenmidport, PORT3, sizeof(listenmidport));

if (options->midsockport) {
sprintf(listenmidport, "%d", options->midsockport);
@@ -551,7 +563,8 @@
}

if (options->multiple) {
- strcpy(listenmidport, "0");
+ //strcpy(listenmidport, "0");
+ strlcpy(listenmidport, "0", sizeof(listenmidport));
}

/* RAC debug */
@@ -816,7 +829,9 @@
if (testOptions->c2sopt) {
setCurrentTest(TEST_C2S);
log_println(1, " <-- %d - C2S throughput test -->", testOptions->child0);
- strcpy(listenc2sport, PORT2);
+ //strcpy(listenc2sport, PORT2);
+ strlcpy(listenc2sport, PORT2, sizeof(listenc2sport));
+

//log protocol validation logs
teststatuses = TEST_STARTED;
@@ -833,7 +848,8 @@
}

if (testOptions->multiple) {
- strcpy(listenc2sport, "0");
+ //strcpy(listenc2sport, "0");
+ strlcpy(listenc2sport, "0", sizeof(listenc2sport));
}

// attempt to bind to a new port and obtain address structure with details of listening port
@@ -936,6 +952,7 @@
log_println(0, "C2S test calling pkt_trace_start() with pd=%d", clilen);
start_packet_trace (recvsfd, testOptions->c2ssockfd, &c2s_childpid, mon_pipe1,
(struct sockaddr *) &cli_addr, clilen, device, &pair, "c2s", options->compress, meta.c2s_ndttrace) ;
+ log_println(0, "--tracefile after packet_trace %s", meta.c2s_ndttrace); //todo change level
}


@@ -953,7 +970,8 @@
//createDir(namebuf, I2AddrPort(sockAddr),options->c2s_logname, namesuffix);
*
*/
- createDir((struct sockaddr *) &cli_addr, clilen,options->c2s_logname, namesuffix);
+ create_client_logdir((struct sockaddr *) &cli_addr, clilen,
+ options->c2s_logname, sizeof(options->c2s_logname), namesuffix, sizeof(namesuffix));

//group = web100_group_find(agent, "read");
//snapArgs.snap = web100_snapshot_alloc(group, conn);
@@ -1156,10 +1174,10 @@
struct sockaddr_storage cli_addr;
/* socklen_t optlen, clilen; */
socklen_t clilen;
- double bytes_written; // bytes written in
the througput test
+ double bytes_written; // bytes written in
the throughput test
double tx_duration; // total time for which data
was txed
double tmptime; // temporary time
store
- double x2cspd; // s->c test throuput
+ double x2cspd; // s->c test throuhput
struct timeval sel_tv; // time
fd_set rfd; // receive file
descriptor
char buff[BUFFSIZE+1]; // message payload buffer
@@ -1218,7 +1236,8 @@
//protolog_status(0,testOptions->child0, testids, teststatuses);
protolog_status(testOptions->child0, testids, teststatuses);

- strcpy(listens2cport, PORT4);
+ //strcpy(listens2cport, PORT4);
+ strlcpy(listens2cport, PORT4, sizeof(listens2cport));

if (testOptions->s2csockport) {
sprintf(listens2cport, "%d", testOptions->s2csockport);
@@ -1228,7 +1247,8 @@
}

if (testOptions->multiple) {
- strcpy(listens2cport, "0");
+ //strcpy(listens2cport, "0");
+ strlcpy(listens2cport, "0",sizeof(listens2cport));
}

// attempt to bind to a new port and obtain address structure with details of listening port
@@ -1343,7 +1363,8 @@
/* End of test code */

// create directory to write web100 snaplog trace
- createDir((struct sockaddr *) &cli_addr, clilen ,options->s2c_logname, snaplogsuffix);
+ create_client_logdir((struct sockaddr *) &cli_addr, clilen ,
+ options->s2c_logname, sizeof(options->s2c_logname), snaplogsuffix, sizeof(snaplogsuffix));

/* Kludge way of nuking Linux route cache. This should be done
* using the sysctl interface.
=======================================
--- /branches/kkumar_code_organize/src/tr-mkmap.c Sun Aug 19 03:26:07
2007
+++ /branches/kkumar_code_organize/src/tr-mkmap.c Fri Oct 14 13:52:19
2011
@@ -40,6 +40,7 @@
#include "tr-tree.h"
#include "usage.h"
#include "logging.h"
+#include "strlutils.h"

struct tr_tree *tr_root, *tr_cur;
char* DefaultTree = NULL;
@@ -634,9 +635,11 @@

hp = gethostbyaddr((char *) &ip_addr, 4, AF_INET);
if (hp == NULL)
- strncpy(c_name, "Unknown Host", 13);
+ //strncpy(c_name, "Unknown Host", 13);
+ strlcpy(c_name, "Unknown Host", sizeof(c_name));
else
- strncpy(c_name, hp->h_name, strlen(hp->h_name));
+ //strncpy(c_name, hp->h_name, strlen(hp->h_name));
+ strlcpy(c_name, hp->h_name, sizeof(c_name));

if (found_node == 1) {
printf("Host %s [%u.%u.%u.%u] is remote eNDT server!\n",
@@ -653,9 +656,11 @@
}
hp = (struct hostent *)gethostbyaddr((char *) &current->ip_addr, 4, AF_INET);
if (hp == NULL)
- strncpy(h_name, "Unknown Host", 13);
+ //strncpy(h_name, "Unknown Host", 13);
+ strlcpy(h_name, "Unknown Host", sizeof(h_name));
else
- strncpy(h_name, hp->h_name, strlen(hp->h_name));
+ //strncpy(h_name, hp->h_name, strlen(hp->h_name));
+ strlcpy(h_name, hp->h_name, sizeof(h_name));

printf("\tThe eNDT server %s [%u.%u.%u.%u] is closest to host %s [%u.%u.%u.%u]\n",
h_name, (current->ip_addr & 0xff), ((current->ip_addr >> 8) & 0xff),
=======================================
--- /branches/kkumar_code_organize/src/utils.c Sun Oct 9 17:00:18 2011
+++ /branches/kkumar_code_organize/src/utils.c Fri Oct 14 13:52:19 2011
@@ -21,6 +21,7 @@
#include <errno.h>

#include "utils.h"
+#include "strlutils.h"

/*
* Function name: check_int
=======================================
--- /branches/kkumar_code_organize/src/web100-admin.c Fri Jun 11 02:48:11 2010
+++ /branches/kkumar_code_organize/src/web100-admin.c Fri Oct 14 13:52:19 2011
@@ -145,11 +145,13 @@

str = strchr(str, ',') +1;
sscanf(str, "%[^,]s", tmpstr);
- strncpy(maxdate, tmpstr, strlen(tmpstr));
+ //strncpy(maxdate, tmpstr, strlen(tmpstr));
+ strlcpy(maxdate, tmpstr, sizeof(maxdate));

str = strchr(str, ',') +1;
sscanf(str, "%[^,]s", tmpstr);
- strncpy(mindate, tmpstr, strlen(tmpstr));
+ //strncpy(mindate, tmpstr, strlen(tmpstr));
+ strlcpy(mindate, tmpstr, sizeof(mindate));

for (i=0; i<strlen(mindate); i++)
if (mindate[i] == '\n')
@@ -199,7 +201,8 @@
}

/* Calculate some values */
- strncpy(date, now, strlen(now));
+ //strncpy(date, now, strlen(now));
+ strlcpy(date, now, sizeof(date));
avgrtt = (double) SumRTT/CountRTT;
rttsec = avgrtt * .001;
loss2 = (double)CongestionSignals/PktsOut;
@@ -226,25 +229,33 @@
mins2cspd = s2cspd;
maxc2sspd = c2sspd;
maxs2cspd = s2cspd;
- strncpy(startdate, date, strlen(date));
+ /*strncpy(startdate, date, strlen(date));
strncpy(maxdate, date, strlen(date));
- strncpy(mindate, date, strlen(date));
+ strncpy(mindate, date, strlen(date));*/
+ strlcpy(startdate, date, sizeof(startdate));
+ strlcpy(maxdate, date, sizeof(maxdate));
+ strlcpy(mindate, date, sizeof(mindate));
}
if (c2sspd > maxc2sspd) {
maxc2sspd = c2sspd;
- strncpy(maxdate, date, strlen(date));
+ //strncpy(maxdate, date, strlen(date));
+ strlcpy(maxdate, date, sizeof(maxdate));
}
if (s2cspd > maxs2cspd) {
maxs2cspd = s2cspd;
- strncpy(maxdate, date, strlen(date));
+ //strncpy(maxdate, date, strlen(date));
+ strlcpy(maxdate, date, sizeof(maxdate));
}
if (c2sspd < minc2sspd) {
minc2sspd = c2sspd;
- strncpy(mindate, date, strlen(date));
+ //strncpy(mindate, date, strlen(date));
+ strlcpy(mindate, date, sizeof(mindate));
+
}
if (s2cspd < mins2cspd) {
mins2cspd = s2cspd;
- strncpy(mindate, date, strlen(date));
+ //strncpy(mindate, date, strlen(date));
+ strlcpy(mindate, date, sizeof(mindate));
}

log_println(1, "Initial counter Values Totalcnt = %d, Total Mismatch = %d, Total Bad Cables = %d",
=======================================
--- /branches/kkumar_code_organize/src/web100-pcap.c Mon Mar 22 20:56:00 2010
+++ /branches/kkumar_code_organize/src/web100-pcap.c Fri Oct 14 13:52:19 2011
@@ -19,6 +19,7 @@
#include <net/if.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
+#include "strlutils.h"

int dumptrace;
pcap_t *pd;
@@ -701,8 +702,8 @@
src_addr = I2AddrSAddr(srcAddr, 0);
/* special check for localhost, set device accordingly */
if (I2SockAddrIsLoopback(sock_addr, saddrlen) > 0)
- strncpy(device, "lo", 3);
-
+ //strncpy(device, "lo", 3);
+ strlcpy(device, "lo", 100); //hardcoding device address to 100, as initialised in main()
if (device == NULL) {
if (pcap_findalldevs(&alldevs, errbuf) == 0) {
for (dp=alldevs; dp!=NULL; dp=dp->next) {
@@ -837,33 +838,41 @@
return;
}

- if (dumptrace == 1) {
+ if (dumptrace == 1) { //todo call create_client_log
fprintf(stderr, "Creating trace file for connection\n");
memset(cmdbuf, 0, 256);
- strncpy(cmdbuf, DataDirName, strlen(DataDirName));
+ //strncpy(cmdbuf, DataDirName, strlen(DataDirName));
+ strlcpy(cmdbuf, DataDirName, sizeof(cmdbuf));
if ((dip = opendir(cmdbuf)) == NULL && errno == ENOENT)
mkdir(cmdbuf, 0755);
closedir(dip);
get_YYYY(dir);
- strncat(cmdbuf, dir, 4);
+ //strncat(cmdbuf, dir, 4);
+ strlcat(cmdbuf, dir, sizeof(cmdbuf));
if ((dip = opendir(cmdbuf)) == NULL && errno == ENOENT)
mkdir(cmdbuf, 0755);
closedir(dip);
- strncat(cmdbuf, "/", 1);
+ //strncat(cmdbuf, "/", 1);
+ strlcat(cmdbuf, "/", sizeof(cmdbuf));
get_MM(dir);
- strncat(cmdbuf, dir, 2);
+ //strncat(cmdbuf, dir, 2);
+ strlcat(cmdbuf, dir, sizeof(cmdbuf));
if ((dip = opendir(cmdbuf)) == NULL && errno == ENOENT)
mkdir(cmdbuf, 0755);
closedir(dip);
- strncat(cmdbuf, "/", 1);
+ //strncat(cmdbuf, "/", 1);
+ strlcat(cmdbuf, "/", sizeof(cmdbuf));
get_DD(dir);
- strncat(cmdbuf, dir, 2);
+ //strncat(cmdbuf, dir, 2);
+ strlcat(cmdbuf, dir, sizeof(cmdbuf));
if ((dip = opendir(cmdbuf)) == NULL && errno == ENOENT)
mkdir(cmdbuf, 0755);
closedir(dip);
- strncat(cmdbuf, "/", 1);
- sprintf(dir, "%s_%s:%d.%s_ndttrace", get_ISOtime(isoTime), namebuf, I2AddrPort(sockAddr), direction);
- strncat(cmdbuf, dir, strlen(dir));
+ //strncat(cmdbuf, "/", 1);
+ strlcat(cmdbuf, "/", sizeof(cmdbuf));
+ sprintf(dir, "%s_%s:%d.%s_ndttrace", get_ISOtime(isoTime, sizeof(isoTime)), namebuf, I2AddrPort(sockAddr), direction);
+ //strncat(cmdbuf, dir, strlen(dir));
+ strlcat(cmdbuf, dir, sizeof(cmdbuf));
pdump = pcap_dump_open(pd, cmdbuf);
fprintf(stderr, "Opening '%s' log fine\n", cmdbuf);
if (pdump == NULL) {
=======================================
--- /branches/kkumar_code_organize/src/web100-util.c Fri Sep 23 13:50:35 2011
+++ /branches/kkumar_code_organize/src/web100-util.c Fri Oct 14 13:52:19 2011
@@ -15,6 +15,7 @@
#include "logging.h"
#include "utils.h"
#include "protocol.h"
+#include "strlutils.h"

/**
* set up the necessary structures for monitoring connections at the
@@ -46,7 +47,8 @@
if ((line[0] == '#') || (line[0] == '\n')) // if newline or comment, ignore
continue;
// copy web100 variable into our array and increment count of read variables
- strncpy(web_vars[count_vars].name, line, (strlen(line)-1));
+ //strncpy(web_vars[count_vars].name, line, (strlen(line)-1));
+ strlcpy(web_vars[count_vars].name, line, sizeof(web_vars[count_vars].name));
count_vars++;
}
fclose(fp);
@@ -123,7 +125,8 @@
// terminate the IP address string
meta.server_ip[(strlen(line)-1)] = 0;
// Add this address to results
- strncat(results, line, strlen(line));
+ //strncat(results, line, strlen(line));
+ strlcat(results, line, (BUFFSIZE+1)); //todo : later: using a "known" hardcoded value for size of results
I2AddrFree(addr); // free memory

// Now perform the above set of functions for client address/service name
@@ -135,7 +138,8 @@
sprintf(line, "%s;", tmpstr);
I2AddrServName(addr, tmpstr, &tmpstrlen);
log_print(3, "Client: %s%s ", line, tmpstr);
- strncat(results, line, strlen(line));
+ //strncat(results, line, strlen(line));
+ strlcat(results, line, (BUFFSIZE+1)); //todo :later: using a "known" hardcoded value for size of results
I2AddrFree(addr);

// get web100 values for the middlebox test result group
@@ -152,7 +156,8 @@
sprintf(line, "%s;", web100_value_to_text(web100_get_var_type(var), buff));
if (strcmp(line, "4294967295;") == 0) // TODO what is this number?
sprintf(line, "%d;", -1);
- strcat(results, line);
+ //strcat(results, line);
+ strlcat(results, line, sizeof(results));
log_print(3, "%s", line);
}
log_println(3, "");
=======================================
--- /branches/kkumar_code_organize/src/web100clt.c Sun May 8 04:04:21
2011
+++ /branches/kkumar_code_organize/src/web100clt.c Fri Oct 14 13:52:19
2011
@@ -17,6 +17,7 @@
#include "test_sfw.h"
#include "test_meta.h"
#include "clt_tests.h"
+#include "strlutils.h"

#ifndef VIEW_DIFF
#define VIEW_DIFF 0.1
@@ -389,9 +390,11 @@
size_t tmpLen;

str = strtok(tmpstr, ";");
- strcpy(ssip, str);
+ //strcpy(ssip, str);
+ strlcpy(ssip, str, sizeof(ssip));
str = strtok(NULL, ";");
- strcpy(scip, str);
+ //strcpy(scip, str);
+ strlcpy(scip, str, sizeof(scip));

str = strtok(NULL, ";");
mss = atoi(str);
@@ -905,14 +908,16 @@
if (check_msg_type("Tests results", MSG_RESULTS, msgType, buff, msgLen)) {
exit(2);
}
- strncat(tmpstr, buff, msgLen);
+ //strncat(tmpstr, buff, msgLen);
+ strlcat(tmpstr, buff, sizeof(tmpstr));
log_println(6, "tmpstr = '%s'", tmpstr);
}

local_addr = I2AddrByLocalSockFD(get_errhandle(), ctlSocket, False);
remote_addr = I2AddrBySockFD(get_errhandle(), ctlSocket, False);
I2AddrFree(server_addr);
- strcpy(varstr, tmpstr);
+ //strcpy(varstr, tmpstr);
+ strlcpy(varstr, tmpstr, sizeof(varstr));
testResults(tests, tmpstr, host);
if (tests & TEST_MID) {
middleboxResults(tmpstr2, local_addr, remote_addr);
=======================================
--- /branches/kkumar_code_organize/src/web100srv.c Sun Oct 9 17:00:18
2011
+++ /branches/kkumar_code_organize/src/web100srv.c Fri Oct 14 13:52:19
2011
@@ -82,7 +82,7 @@
#include "test_sfw.h"
#include "ndt_odbc.h"
#include "runningtest.h"
-
+#include "strlutils.h"

static char lgfn[256];
static char wvfn[256];
@@ -1342,8 +1342,12 @@
send_msg(ctlsockfd, MSG_LOGOUT, "", 0);

// Copy collected values into the meta data structures
- sprintf(meta.date, "%s", get_ISOtime(isoTime));
+ sprintf(meta.date, "%s", get_ISOtime(isoTime,sizeof(isoTime)));
+//todo remove debug
+ log_println(0, "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(0, "2. meta.clientip =%s:%s:%d", meta.client_ip, rmt_host);
+//todo remove debug
memset(tmpstr, 0, 255);
sprintf(tmpstr,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,",
(int)s2c2spd,(int)s2cspd,(int)c2sspd, Timeouts, SumRTT, CountRTT, PktsRetrans,
@@ -1354,23 +1358,28 @@
MaxRwinRcvd, Sndbuf, MaxCwnd, SndLimTimeRwin, SndLimTimeCwnd,
SndLimTimeSender, DataBytesOut, SndLimTransRwin, SndLimTransCwnd,
SndLimTransSender, MaxSsthresh, CurrentRTO, CurrentRwinRcvd);
- strncat(meta.summary, tmpstr, strlen(tmpstr));
+ //strncat(meta.summary, tmpstr, strlen(tmpstr));
+ strlcat(meta.summary, tmpstr, sizeof(meta.summary));
memset(tmpstr, 0, 255);
sprintf(tmpstr,"%d,%d,%d,%d,%d",
link, mismatch, bad_cable, half_duplex, congestion);
- strncat(meta.summary, tmpstr, strlen(tmpstr));
+ //strncat(meta.summary, tmpstr, strlen(tmpstr));
+ strlcat(meta.summary, tmpstr, sizeof(meta.summary));
memset(tmpstr, 0, 255);
sprintf(tmpstr, ",%d,%d,%d,%d,%d,%d,%d,%d,%d", c2sdata, c2sack, s2cdata, s2cack,
CongestionSignals, PktsOut, MinRTT, RcvWinScale, autotune);
- strncat(meta.summary, tmpstr, strlen(tmpstr));
+ //strncat(meta.summary, tmpstr, strlen(tmpstr));
+ strlcat(meta.summary, tmpstr, sizeof(meta.summary));
memset(tmpstr, 0, 255);
sprintf(tmpstr, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", CongAvoid, CongestionOverCount, MaxRTT,
OtherReductions, CurTimeoutCount, AbruptTimeouts, SendStall, SlowStart,
SubsequentTimeouts, ThruBytesAcked);
- strncat(meta.summary, tmpstr, strlen(tmpstr));
+ //strncat(meta.summary, tmpstr, strlen(tmpstr));
+ strlcat(meta.summary, tmpstr, sizeof(meta.summary));
memset(tmpstr, 0, 255);
sprintf(tmpstr, ",%d,%d,%d", peaks.min, peaks.max, peaks.amount);
- strncat(meta.summary, tmpstr, strlen(tmpstr));
+ //strncat(meta.summary, tmpstr, strlen(tmpstr));
+ strlcat(meta.summary, tmpstr, sizeof(meta.summary));
writeMeta(options.compress, cputime, options.snaplog, dumptrace);

// Write into log files, DB
@@ -2171,6 +2180,9 @@
memset(new_child, 0, sizeof(struct ndtchild));
tt = time(0);
name = tmpstr;
+ //todo remove debug log
+ log_println(" CLIENT CLIENT CLIENT IP=%s",tmpstr);
+
rmt_host = tmpstr;

// At this point we have received a connection from a client, meaning that
@@ -2244,8 +2256,10 @@
log_println(6, "creating new child - semaphore locked");
/*sigprocmask(SIG_BLOCK, &newmask, &oldmask); */
new_child->pid = chld_pid;
- strncpy(new_child->addr, rmt_host, strlen(rmt_host));
- strncpy(new_child->host, name, strlen(name));
+ /* strncpy(new_child->addr, rmt_host, strlen(rmt_host));
+ strncpy(new_child->host, name, strlen(name));*/
+ strlcpy(new_child->addr, rmt_host, sizeof(new_child->addr));
+ strlcpy(new_child->host, name, sizeof(new_child->host));

// compute start time based in the number of waiting clients
// set other properties on this child process
@@ -2534,30 +2548,38 @@
I2AddrFree(tmp_addr);
memset(cputimelog, 0, 256);
if (cputime) {
- strncpy(cputimelog, DataDirName, strlen(DataDirName));
+ //strncpy(cputimelog, DataDirName, strlen(DataDirName));
+ strlcpy(cputimelog, DataDirName, sizeof(cputimelog));
if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
mkdir(cputimelog, 0755);
closedir(dp);
get_YYYY(dir);
- strncat(cputimelog, dir, 4);
+ //strncat(cputimelog, dir, 4);
+ strlcat(cputimelog, dir, sizeof(cputimelog));
if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
mkdir(cputimelog, 0755);
closedir(dp);
- strncat(cputimelog, "/", 1);
+ //strncat(cputimelog, "/", 1);
+ strncat(cputimelog, "/", sizeof(cputimelog));
get_MM(dir);
- strncat(cputimelog, dir, 2);
+ //strncat(cputimelog, dir, 2);
+ strlcat(cputimelog, dir, sizeof(cputimelog));
if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
mkdir(cputimelog, 0755);
closedir(dp);
- strncat(cputimelog, "/", 1);
+ //strncat(cputimelog, "/", 1);
+ strlcat(cputimelog, "/", sizeof(cputimelog));
get_DD(dir);
- strncat(cputimelog, dir, 2);
+ //strncat(cputimelog, dir, 2);
+ strlcat(cputimelog, dir, sizeof(cputimelog));
if ((dp = opendir(cputimelog)) == NULL && errno == ENOENT)
mkdir(cputimelog, 0755);
closedir(dp);
- strncat(cputimelog, "/", 1);
- sprintf(dir, "%s_%s:%d.cputime", get_ISOtime(isoTime), name,
testPort);
- strncat(cputimelog, dir, strlen(dir));
+ //strncat(cputimelog, "/", 1);
+ strncat(cputimelog, "/", sizeof(cputimelog));
+ sprintf(dir, "%s_%s:%d.cputime", get_ISOtime(isoTime, sizeof(isoTime)), name, testPort);
+ //strncat(cputimelog, dir, strlen(dir));
+ strlcat(cputimelog, dir, sizeof(cputimelog));
memcpy(meta.CPU_time, dir, strlen(dir));
if (pthread_create(&workerThreadId, NULL, cputimeWorker, (void*) cputimelog)) {
log_println(0, "Cannot create worker thread for writing cpu usage!");


  • [ndt-dev] [ndt] r719 committed - Buffer overflow prevention:, ndt, 10/14/2011

Archive powered by MHonArc 2.6.16.

Top of Page