more sprintf bashing
authorNathan Bryant <loanshark@uncensored.citadel.org>
Tue, 12 Mar 2002 02:56:17 +0000 (02:56 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Tue, 12 Mar 2002 02:56:17 +0000 (02:56 +0000)
citadel/citserver.c
citadel/serv_upgrade.c
citadel/serv_vandelay.c
citadel/serv_vcard.c
citadel/setup.c
citadel/stats.c
citadel/support.c
citadel/support.h

index ddb966012b1d878c0f66f01cc384c09873305c8c..800e043a7f841eae614ebd86077327357dc1c5a0 100644 (file)
@@ -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]);
 
index 1a6323d4f6344dc3d25285d25417b5607c5ab01f..618b5a2dbec60416a37fd5a1c835132cc72c1813 100644 (file)
@@ -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"
index 469612eaf47379727d49ec8085104632f9027fa6..3e33faa93780f7ab7e395083886ae4929e287a11 100644 (file)
@@ -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);
index b4cbe6269c58736ff2147d74d51ed59453fe7028..c952f5d723cc99b95250768cc3e7cce986fed185 100644 (file)
@@ -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");
index e35318ca1e4478b340e1d0e89bff174937b147d9..ef0f70ab1440d35246a7f3f2456242a6cee4771b 100644 (file)
@@ -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);
index 3e3011d6ee6d584053075810a930b85cf83cf7c4..cd9c6e26a8ce76d402d221e5bcfb9c0e02d06dec 100644 (file)
@@ -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]);
index 3262890b2cabec271475df30acbd6b45a5c5b1e5..1e176ad959ce8b0c5904f14c2dedc4d6d2bb94ba 100644 (file)
@@ -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<numdirs; ++a) {
-               sprintf(buf,"cd %s; exec ls",dirs[a]);
+               snprintf(buf, sizeof buf, "cd %s; exec ls",dirs[a]);
                ls = (FILE *) popen(buf,"r");
                if (ls != NULL) {
                        while(fgets(buf,sizeof buf,ls)!=NULL) {
@@ -119,7 +120,7 @@ void mesg_locate(char *targ, char *searchfor, int numdirs, char **dirs)
                                        buf[strlen(buf)-1] = 0;
                                if (!strcasecmp(buf,searchfor)) {
                                        pclose(ls);
-                                       sprintf(targ,"%s/%s",dirs[a],buf);
+                                       snprintf(targ,n,"%s/%s",dirs[a],buf);
                                        return;
                                        }
                                }
@@ -138,7 +139,7 @@ char *strerror(int e)
 {
        static char buf[32];
 
-       sprintf(buf,"errno = %d",e);
+       snprintf(buf,sizeof buf,"errno = %d",e);
        return(buf);
        }
 #endif
index 582e9c3360618131cfc6fedf6e800c5a13884bdc..a63f8723c6884d5ace0573abb8c4ffc2bc5afdf3 100644 (file)
@@ -2,4 +2,5 @@
 void strproc (char *string);
 int getstring (FILE *fp, char *string);
 int pattern2 (char *search, char *patn);
-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);