More string cleanups.

In bluewave.c mostly.  There are a few places left where sprintf()
is called directly; these should be recast in terms of a stralloc
or possibly strlcat.

One small whitespace change in www_files.c.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
This commit is contained in:
Dan Cross 2018-10-14 13:24:09 +00:00 committed by Andrew Pamment
parent 40570f0fd0
commit 9bfc4ffbe5
2 changed files with 33 additions and 25 deletions

View File

@ -87,13 +87,13 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI
while (sqlite3_step(res) == SQLITE_ROW) {
memset(&fti, 0, sizeof(FTI_REC));
strncpy(fti.from, sqlite3_column_text(res, 0), 35);
strncpy(fti.to, gUser->loginname, 35);
strncpy(fti.subject, sqlite3_column_text(res, 1), 71);
strlcpy(fti.from, sqlite3_column_text(res, 0), sizeof fti.from);
strlcpy(fti.to, gUser->loginname, sizeof fti.to);
strlcpy(fti.subject, sqlite3_column_text(res, 1), fti.subject);
thetime = sqlite3_column_int(res, 2);
localtime_r((time_t *)&thetime, &timeStruct);
sprintf(fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min);
snprintf(fti.date, sizeof fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min);
fti.msgnum = converts((tWORD)sqlite3_column_int(res, 4));
body = strdup(sqlite3_column_text(res, 3));
fti.replyto = 0;
@ -209,25 +209,25 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file
memset(&fti, 0, sizeof(FTI_REC));
if (msghs->msgs[k]->from != NULL) {
strncpy(fti.from, msghs->msgs[k]->from, 35);
strlcpy(fti.from, msghs->msgs[k]->from, sizeof fti.from);
} else {
sprintf(fti.from, "(Missing From)");
strlcpy(fti.from, "(Missing From)", sizeof fti.from);
}
if (msghs->msgs[k]->to != NULL) {
strncpy(fti.to, msghs->msgs[k]->to, 35);
strlcpy(fti.to, msghs->msgs[k]->to, sizeof fti.to);
} else {
sprintf(fti.to, "(Missing To)");
strlcpy(fti.to, "(Missing To)", sizeof sti.to);
}
if (msghs->msgs[k]->subject != NULL) {
strncpy(fti.subject, msghs->msgs[k]->subject, 71);
strlcpy(fti.subject, msghs->msgs[k]->subject, fti.subject);
} else {
sprintf(fti.subject, "(Missing Subject)");
strlcpy(fti.subject, "(Missing Subject)", sizeof fti.subject);
}
localtime_r((time_t *)&msghs->msgs[k]->msg_h->DateWritten, &timeStruct);
sprintf(fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min);
snprintf(fti.date, sizeof fti.date, "%02d-%s-%04d %02d:%02d", timeStruct.tm_mday, month_name[timeStruct.tm_mon], timeStruct.tm_year + 1900, timeStruct.tm_hour, timeStruct.tm_min);
fti.msgnum = converts((tWORD)msghs->msgs[k]->msg_h->MsgNum);
fti.replyto = 0;
fti.replyat = 0;
@ -345,7 +345,7 @@ void bwave_create_packet() {
hdr.ver = PACKET_LEVEL;
strncpy(hdr.loginname, gUser->loginname, 42);
//strncpy(hdr.aliasname, gUser->loginname, 42);
snprintf(hdr.aliasname, 42, "%s %s", gUser->firstname, gUser->lastname);
snprintf(hdr.aliasname, sizeof hdr.aliasname, "%s %s", gUser->firstname, gUser->lastname);
hdr.zone = converts(conf.main_aka->zone);
hdr.node = converts(conf.main_aka->node);
hdr.net = converts(conf.main_aka->net);
@ -397,7 +397,7 @@ void bwave_create_packet() {
memcpy(area->echotag, "PRIVATE_EMAIL", 13);
strncpy(area->title, "Private Email", 49);
strlcpy(area->title, "Private Email", 49);
flags |= INF_POST;
flags |= INF_NO_PUBLIC;
flags |= INF_SCANNING;
@ -605,7 +605,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
JAM_PutSubfield(jsp, &jsf);
if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NEWSGROUP_AREA) {
sprintf(buffer, "ALL");
strlcpy(buffer, "ALL", sizeof buffer);
jsf.LoID = JAMSFLD_RECVRNAME;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
@ -631,12 +631,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
if (conf.mail_conferences[confr]->nettype == NETWORK_FIDO) {
if (conf.mail_conferences[confr]->fidoaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point);
} else {
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node);
}
@ -646,7 +648,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
jsf.Buffer = (char *)buffer;
JAM_PutSubfield(jsp, &jsf);
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point,
@ -659,7 +662,7 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
JAM_PutSubfield(jsp, &jsf);
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
} else if (conf.mail_conferences[confr]->nettype == NETWORK_MAGI) {
sprintf(buffer, "%d", conf.mail_conferences[confr]->maginode);
snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[confr]->maginode);
jsf.LoID = JAMSFLD_OADDRESS;
jsf.HiID = 0;
jsf.DatLen = strlen(buffer);
@ -687,12 +690,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
jmh.Attribute |= JAM_MSG_PRIVATE;
if (conf.mail_conferences[confr]->fidoaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point);
} else {
sprintf(buffer, "%d:%d/%d", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node);
}
@ -704,12 +709,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
if (destaddr != NULL) {
if (destaddr->point) {
sprintf(buffer, "%d:%d/%d.%d", destaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d",
destaddr->zone,
destaddr->net,
destaddr->node,
destaddr->point);
} else {
sprintf(buffer, "%d:%d/%d", destaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d",
destaddr->zone,
destaddr->net,
destaddr->node);
}
@ -720,7 +727,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char
JAM_PutSubfield(jsp, &jsf);
}
sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[confr]->fidoaddr->zone,
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx",
conf.mail_conferences[confr]->fidoaddr->zone,
conf.mail_conferences[confr]->fidoaddr->net,
conf.mail_conferences[confr]->fidoaddr->node,
conf.mail_conferences[confr]->fidoaddr->point,
@ -925,7 +933,7 @@ void bwave_upload_reply() {
}
body[bpos] = '\0';
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
snprintf(buffer, sizeof buffer, "%s/email.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);

View File

@ -350,7 +350,7 @@ char *www_files_display_listing(int dir, int sub) {
size /= 1024;
c = 'G';
}
stralloc_cat_long(&page, size);
stralloc_cat_long(&page, size);
stralloc_append1(&page, c);
stralloc_cats(&page, "</td>");