From 1eea10377d12301caa593ac2076e5f7021412e88 Mon Sep 17 00:00:00 2001 From: Nathan Bryant Date: Tue, 12 Mar 2002 02:56:17 +0000 Subject: [PATCH] more sprintf bashing --- citadel/citserver.c | 4 ++-- citadel/serv_upgrade.c | 2 +- citadel/serv_vandelay.c | 8 ++++---- citadel/serv_vcard.c | 12 ++++++------ citadel/setup.c | 18 +++++++++--------- citadel/stats.c | 2 +- citadel/support.c | 9 +++++---- citadel/support.h | 3 ++- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index ddb966012..800e043a7 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -504,7 +504,7 @@ void cmd_mesg(char *mname) dirs[1]=mallok(64); strcpy(dirs[0],"messages"); strcpy(dirs[1],"help"); - mesg_locate(targ,buf,2,dirs); + mesg_locate(targ,sizeof targ,buf,2,(const char **)dirs); phree(dirs[0]); phree(dirs[1]); @@ -555,7 +555,7 @@ void cmd_emsg(char *mname) dirs[1]=mallok(64); strcpy(dirs[0],"messages"); strcpy(dirs[1],"help"); - mesg_locate(targ,buf,2,dirs); + mesg_locate(targ,sizeof targ,buf,2,(const char**)dirs); phree(dirs[0]); phree(dirs[1]); diff --git a/citadel/serv_upgrade.c b/citadel/serv_upgrade.c index 1a6323d4f..618b5a2db 100644 --- a/citadel/serv_upgrade.c +++ b/citadel/serv_upgrade.c @@ -94,7 +94,7 @@ void do_pre555_usersupp_upgrade(void) { putuser(&newus); /* write the vcard */ - sprintf(vcard, + snprintf(vcard, sizeof vcard, "Content-type: text/x-vcard\n\n" "begin:vcard\n" "n:%s\n" diff --git a/citadel/serv_vandelay.c b/citadel/serv_vandelay.c index 469612eaf..3e33faa93 100644 --- a/citadel/serv_vandelay.c +++ b/citadel/serv_vandelay.c @@ -122,9 +122,9 @@ void artv_export_rooms(void) { * this will be handled by exporting the reference count, not by * exporting the message multiple times.) */ - sprintf(cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2); + snprintf(cmd, sizeof cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2); system(cmd); - sprintf(cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1); + snprintf(cmd, sizeof cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1); system(cmd); } @@ -205,7 +205,7 @@ void artv_export_message(long msgnum) { /* write it in base64 */ strcpy(tempfile, tmpnam(NULL)); - sprintf(buf, "./base64 -e >%s", tempfile); + snprintf(buf, sizeof buf, "./base64 -e >%s", tempfile); fp = popen(buf, "w"); fwrite(smr.ser, smr.len, 1, fp); pclose(fp); @@ -484,7 +484,7 @@ void artv_import_message(void) { /* decode base64 message text */ strcpy(tempfile, tmpnam(NULL)); - sprintf(buf, "./base64 -d >%s", tempfile); + snprintf(buf, sizeof buf, "./base64 -d >%s", tempfile); fp = popen(buf, "w"); while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) { fprintf(fp, "%s\n", buf); diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index b4cbe6269..c952f5d72 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -88,7 +88,7 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg, if (msg->cm_fields['A'] == NULL) return; if (msg->cm_fields['N'] == NULL) return; - sprintf(citadel_address, "%s @ %s", + snprintf(citadel_address, sizeof citadel_address, "%s @ %s", msg->cm_fields['A'], msg->cm_fields['N']); v = vcard_load(msg->cm_fields['M']); @@ -289,7 +289,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) { if (msg->cm_fields['E'] != NULL) phree(msg->cm_fields['E']); - sprintf(buf, VCARD_EXT_FORMAT, + snprintf(buf, sizeof buf, VCARD_EXT_FORMAT, msg->cm_fields['A'], NODENAME); msg->cm_fields['E'] = strdoop(buf); @@ -503,7 +503,7 @@ void cmd_regi(char *argbuf) { ++a; } - sprintf(tmpaddress, ";;%s;%s;%s;%s;%s", + snprintf(tmpaddress, sizeof tmpaddress, ";;%s;%s;%s;%s;%s", tmpaddr, tmpcity, tmpstate, tmpzip, tmpcountry); vcard_set_prop(my_vcard, "adr", tmpaddress, 0); vcard_write_user(&CC->usersupp, my_vcard); @@ -564,7 +564,7 @@ void cmd_greg(char *argbuf) cprintf("%s\n", s ? s : " "); /* name */ s = vcard_get_prop(v, "adr", 0, 0, 0); - sprintf(adr, "%s", s ? s : " ");/* address... */ + snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */ extract_token(buf, adr, 2, ';'); cprintf("%s\n", buf); /* street */ @@ -589,7 +589,7 @@ void cmd_greg(char *argbuf) s = vcard_get_prop(v, "email;internet", 0, 0, 0); cprintf("%s\n", s ? s : " "); s = vcard_get_prop(v, "adr", 0, 0, 0); - sprintf(adr, "%s", s ? s : " ");/* address... */ + snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */ extract_token(buf, adr, 6, ';'); cprintf("%s\n", buf); /* country */ @@ -618,7 +618,7 @@ void vcard_purge(char *username, long usernum) { msg->cm_fields['N'] = strdoop(NODENAME); msg->cm_fields['M'] = strdoop("Purge this vCard\n"); - sprintf(buf, VCARD_EXT_FORMAT, msg->cm_fields['A'], NODENAME); + snprintf(buf, sizeof buf, VCARD_EXT_FORMAT, msg->cm_fields['A'], NODENAME); msg->cm_fields['E'] = strdoop(buf); msg->cm_fields['S'] = strdoop("CANCEL"); diff --git a/citadel/setup.c b/citadel/setup.c index e35318ca1..ef0f70ab1 100644 --- a/citadel/setup.c +++ b/citadel/setup.c @@ -430,7 +430,7 @@ void check_services_entry(void) char question[128]; FILE *sfp; - sprintf(question, + snprintf(question, sizeof question, "There is no '%s' entry in /etc/services. Would you like to add one?", SERVICE_NAME); @@ -464,7 +464,7 @@ void check_inittab_entry(void) char entryname[5]; /* Determine the fully qualified path name of citserver */ - sprintf(looking_for, "%s/citserver ", BBSDIR); + snprintf(looking_for, sizeof looking_for, "%s/citserver ", BBSDIR); /* Pound through /etc/inittab line by line. Set have_entry to 1 if * an entry is found which we believe starts citserver. @@ -494,7 +494,7 @@ void check_inittab_entry(void) return; /* Otherwise, prompt the user to create an entry. */ - sprintf(question, + snprintf(question, sizeof question, "There is no '%s' entry in /etc/inittab.\n" "Would you like to add one?", looking_for); @@ -502,7 +502,7 @@ void check_inittab_entry(void) return; /* Generate a unique entry name for /etc/inittab */ - sprintf(entryname, "c0"); + snprintf(entryname, sizeof entryname, "c0"); do { ++entryname[1]; if (entryname[1] > '9') { @@ -514,7 +514,7 @@ void check_inittab_entry(void) return; } } - sprintf(buf, + snprintf(buf, sizeof buf, "grep %s: /etc/inittab >/dev/null 2>&1", entryname); } while (system(buf) == 0); @@ -573,7 +573,7 @@ void set_str_val(int msgpos, char str[]) void set_int_val(int msgpos, int *ip) { char buf[16]; - sprintf(buf, "%d", (int) *ip); + snprintf(buf, sizeof buf, "%d", (int) *ip); set_str_val(msgpos, buf); *ip = atoi(buf); } @@ -582,7 +582,7 @@ void set_int_val(int msgpos, int *ip) void set_char_val(int msgpos, char *ip) { char buf[16]; - sprintf(buf, "%d", (int) *ip); + snprintf(buf, sizeof buf, "%d", (int) *ip); set_str_val(msgpos, buf); *ip = (char) atoi(buf); } @@ -591,7 +591,7 @@ void set_char_val(int msgpos, char *ip) void set_long_val(int msgpos, long int *ip) { char buf[16]; - sprintf(buf, "%ld", *ip); + snprintf(buf, sizeof buf, "%ld", *ip); set_str_val(msgpos, buf); *ip = atol(buf); } @@ -933,7 +933,7 @@ NEW_INST: progress("Setting file permissions", 1, 5); chown("citadel.config", config.c_bbsuid, gid); progress("Setting file permissions", 2, 5); - sprintf(aaa, + snprintf(aaa, sizeof aaa, "find . | grep -v chkpwd | xargs chown %ld:%ld 2>/dev/null", (long)config.c_bbsuid, (long)gid); system(aaa); diff --git a/citadel/stats.c b/citadel/stats.c index 3e3011d6e..cd9c6e26a 100644 --- a/citadel/stats.c +++ b/citadel/stats.c @@ -344,7 +344,7 @@ int main(int argc, char **argv) fakeargs[0] = "whobbs"; fakeargs[1] = "localhost"; fakeargs[2] = malloc(64); - sprintf(fakeargs[2], "%d", config.c_port_number); + snprintf(fakeargs[2], 64, "%d", config.c_port_number); fakeargs[3] = NULL; attach_to_server(3, fakeargs, hostbuf, portbuf); free(fakeargs[2]); diff --git a/citadel/support.c b/citadel/support.c index 3262890b2..1e176ad95 100644 --- a/citadel/support.c +++ b/citadel/support.c @@ -104,14 +104,15 @@ int pattern2(char *search, char *patn) /* * mesg_locate() - locate a message or help file, case insensitive */ -void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs) +void mesg_locate(char *targ, size_t n, const char *searchfor, + int numdirs, const char * const *dirs) { int a; char buf[SIZ]; FILE *ls; for (a=0; a