From: Nathan Bryant Date: Tue, 12 Mar 2002 01:33:42 +0000 (+0000) Subject: - pass -Wcast-qual to gcc X-Git-Tag: v7.86~6493 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=22e1d65797ddb854eb2be4d33bfd4717329eb521 - pass -Wcast-qual to gcc - more sprintf bashing --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 5b1627b96..114dc091d 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,8 @@ $Log$ + Revision 590.140 2002/03/12 01:33:42 nbryant + - pass -Wcast-qual to gcc + - more sprintf bashing + Revision 590.139 2002/03/12 00:03:43 nbryant more sprintf removals @@ -3437,3 +3441,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/configure.ac b/citadel/configure.ac index 7b3452b21..14083d78a 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -100,10 +100,10 @@ dnl Set up system-dependent compiler flags. if test "$GCC" = yes; then case "$host" in *-*-solaris*|alpha*-dec-osf*) - CFLAGS="$CFLAGS -Wall -Wcast-align -Wno-char-subscripts" + CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wno-char-subscripts" ;; *) - CFLAGS="$CFLAGS -Wall -Wcast-align -Wstrict-prototypes" + CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wstrict-prototypes" ;; esac fi diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index 741c563fe..93337b3b1 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -157,7 +157,7 @@ void unfold_rfc822_field(char *field) { * Split an RFC822-style address into userid, host, and full name * */ -void process_rfc822_addr(char *rfc822, char *user, char *node, char *name) +void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name) { int a; diff --git a/citadel/internet_addressing.h b/citadel/internet_addressing.h index d873b972d..42b7c5bd1 100644 --- a/citadel/internet_addressing.h +++ b/citadel/internet_addressing.h @@ -14,7 +14,7 @@ struct internet_address_list { int fuzzy_match(struct usersupp *us, char *matchstring); -void process_rfc822_addr(char *rfc822, char *user, char *node, char *name); +void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name); char *rfc822_fetch_field(char *rfc822, char *fieldname); int IsDirectory(char *addr); diff --git a/citadel/locate_host.c b/citadel/locate_host.c index f78786843..7e30b46f2 100644 --- a/citadel/locate_host.c +++ b/citadel/locate_host.c @@ -31,7 +31,8 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr) { struct hostent *ch; - char *i; + const char *i; + char *j; int a1, a2, a3, a4; lprintf(9, "locate_host() called\n"); @@ -40,10 +41,10 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr) begin_critical_section(S_NETDB); #endif - if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) == + if ((ch = gethostbyaddr((const char *) addr, sizeof(*addr), AF_INET)) == NULL) { bad_dns: - i = (char *) addr; + i = (const char *) addr; a1 = ((*i++) & 0xff); a2 = ((*i++) & 0xff); a3 = ((*i++) & 0xff); @@ -53,9 +54,9 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr) section */ } /* check if the forward DNS agrees; if not, they're spoofing */ - i = strdoop(ch->h_name); - ch = gethostbyname(i); - phree(i); + j = strdoop(ch->h_name); + ch = gethostbyname(j); + phree(j); if (ch == NULL) goto bad_dns; diff --git a/citadel/messages.c b/citadel/messages.c index 8da83b3cc..1a4e6308b 100644 --- a/citadel/messages.c +++ b/citadel/messages.c @@ -50,7 +50,7 @@ struct cittext { }; void sttybbs(int cmd); -int haschar(char *st, int ch); +int haschar(const char *st, int ch); int checkpagin(int lp, int pagin, int height); void getline(char *string, int lim); void formout(char *name); diff --git a/citadel/routines.c b/citadel/routines.c index 55e8f94d2..c3c9f6574 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -122,14 +122,14 @@ void edituser(void) int newnow = 0; newprompt("User name: ",who,25); -AGUP: sprintf(buf,"AGUP %s",who); +AGUP: snprintf(buf, sizeof buf, "AGUP %s",who); serv_puts(buf); serv_gets(buf); if (buf[0]!='2') { scr_printf("%s\n",&buf[4]); scr_printf("Do you want to create this user? "); if (yesno()) { - sprintf(buf, "CREU %s", who); + snprintf(buf, sizeof buf, "CREU %s", who); serv_puts(buf); serv_gets(buf); if (buf[0] == '2') { @@ -171,7 +171,7 @@ AGUP: sprintf(buf,"AGUP %s",who); userpurge = intprompt("Purge time (in days, 0 for system default", userpurge, 0, INT_MAX); - sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d", + snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d", who, pass, flags, timescalled, posted, axlevel, usernum, (long)lastcall, userpurge); serv_puts(buf); @@ -213,7 +213,7 @@ void enter_config(int mode) int width, height, flags, filter; char buf[128]; - sprintf(buf,"GETU"); + snprintf(buf, sizeof buf, "GETU"); serv_puts(buf); serv_gets(buf); if (buf[0]!='2') { @@ -283,7 +283,7 @@ void enter_config(int mode) } } - sprintf(buf,"SETU %d|%d|%d|%d",width,height,flags,filter); + snprintf(buf, sizeof buf, "SETU %d|%d|%d|%d",width,height,flags,filter); serv_puts(buf); serv_gets(buf); if (buf[0]!='2') scr_printf("%s\n",&buf[4]); @@ -380,7 +380,7 @@ char *strerror(int e) { static char buf[128]; - sprintf(buf,"errno = %d",e); + snprintf(buf, sizeof buf, "errno = %d",e); return(buf); } #endif @@ -558,7 +558,7 @@ int nukedir(char *dirname) } while (d = readdir(dp), d != NULL) { - sprintf(filename, "%s/%s", dirname, d->d_name); + snprintf(filename, sizeof filename, "%s/%s", dirname, d->d_name); unlink(filename); } diff --git a/citadel/routines.h b/citadel/routines.h index 8e37f8976..af723b694 100644 --- a/citadel/routines.h +++ b/citadel/routines.h @@ -10,3 +10,4 @@ int nukedir(char *dirname); int num_parms(char *source); void strproc(char *string); void back(int spaces); +void progress(long int curr, long int cmax); diff --git a/citadel/routines2.c b/citadel/routines2.c index dd314c964..e66ac3ce0 100644 --- a/citadel/routines2.c +++ b/citadel/routines2.c @@ -43,16 +43,7 @@ #include "snprintf.h" #endif #include "screen.h" - -void interr(int errnum); -void strprompt(char *prompt, char *str, int len); -void newprompt(char *prompt, char *str, int len); -void sttybbs(int cmd); -int inkey(void); -void serv_write(char *buf, int nbytes); -int haschar(char *st, int ch); -void progress(long int curr, long int cmax); -int yesno(void); +#include "client_crypto.h" extern char temp[]; extern char tempdir[]; diff --git a/citadel/sendcommand.c b/citadel/sendcommand.c index 0ea558c06..01b4d5730 100644 --- a/citadel/sendcommand.c +++ b/citadel/sendcommand.c @@ -111,7 +111,7 @@ void np_attach_to_server(void) attach_to_server(1, args, hostbuf, portbuf); serv_gets(buf); fprintf(stderr, "%s\n", &buf[4]); - sprintf(buf, "IPGM %d", config.c_ipgm_secret); + snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret); serv_puts(buf); serv_gets(buf); fprintf(stderr, "%s\n", &buf[4]); diff --git a/citadel/serv_bio.c b/citadel/serv_bio.c index 635a48ed0..b8f812a3c 100644 --- a/citadel/serv_bio.c +++ b/citadel/serv_bio.c @@ -60,7 +60,7 @@ void cmd_ebio(char *cmdbuf) { return; } - sprintf(buf,"./bio/%ld",CC->usersupp.usernum); + snprintf(buf, sizeof buf, "./bio/%ld",CC->usersupp.usernum); fp = fopen(buf,"w"); if (fp == NULL) { cprintf("%d Cannot create file\n",ERROR); @@ -87,7 +87,7 @@ void cmd_rbio(char *cmdbuf) cprintf("%d No such user.\n",ERROR+NO_SUCH_USER); return; } - sprintf(buf,"./bio/%ld",ruser.usernum); + snprintf(buf, sizeof buf, "./bio/%ld",ruser.usernum); cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS, ruser.fullname, ruser.usernum, ruser.axlevel, diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index 13a18636f..7c9965ad5 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -335,7 +335,7 @@ int PurgeRooms(void) { while (RoomPurgeList != NULL) { if (getroom(&qrbuf, RoomPurgeList->name) == 0) { transcript=reallok(transcript, strlen(transcript)+SIZ); - sprintf(&transcript[strlen(transcript)], " %s\n", + snprintf(&transcript[strlen(transcript)], SIZ, " %s\n", qrbuf.QRname); delete_room(&qrbuf); } @@ -433,7 +433,7 @@ int PurgeUsers(void) { while (UserPurgeList != NULL) { transcript=reallok(transcript, strlen(transcript)+SIZ); - sprintf(&transcript[strlen(transcript)], " %s\n", + snprintf(&transcript[strlen(transcript)], SIZ, " %s\n", UserPurgeList->name); purge_user(UserPurgeList->name); pptr = UserPurgeList->next; diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 381649b9d..b3804ffbe 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -543,7 +543,7 @@ void imap_lsub(int num_parms, char *parms[]) { cprintf("%s BAD arguments invalid\r\n", parms[0]); return; } - sprintf(pattern, "%s%s", parms[2], parms[3]); + snprintf(pattern, sizeof pattern, "%s%s", parms[2], parms[3]); if (strlen(parms[3])==0) { cprintf("* LIST (\\Noselect) \"|\" \"\"\r\n"); @@ -592,7 +592,7 @@ void imap_list(int num_parms, char *parms[]) { cprintf("%s BAD arguments invalid\r\n", parms[0]); return; } - sprintf(pattern, "%s%s", parms[2], parms[3]); + snprintf(pattern, sizeof pattern, "%s%s", parms[2], parms[3]); if (strlen(parms[3])==0) { cprintf("* LIST (\\Noselect) \"|\" \"\"\r\n"); diff --git a/citadel/serv_network.c b/citadel/serv_network.c index 164e890c9..67baa62a2 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -215,7 +215,8 @@ void write_network_map(void) { serialized_map = reallok(serialized_map, (strlen(serialized_map)+SIZ) ); if (strlen(nmptr->nodename) > 0) { - sprintf(&serialized_map[strlen(serialized_map)], + snprintf(&serialized_map[strlen(serialized_map)], + SIZ, "%s|%ld|%s\n", nmptr->nodename, (long)nmptr->lastcontact, @@ -424,15 +425,16 @@ void network_spool_msg(long msgnum, void *userdata) { (long)instr_len); abort(); } - sprintf(instr, + snprintf(instr, instr_len, "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n" "bounceto|postmaster@%s\n" , SPOOLMIME, msgnum, (long)time(NULL), config.c_fqdn ); /* Generate delivery instructions for each recipient */ for (nptr = sc->listrecps; nptr != NULL; nptr = nptr->next) { - sprintf(&instr[strlen(instr)], "remote|%s|0||\n", - nptr->name); + size_t tmp = strlen(instr); + snprintf(&instr[tmp], instr_len - tmp, + "remote|%s|0||\n", nptr->name); } /* @@ -458,6 +460,7 @@ void network_spool_msg(long msgnum, void *userdata) { msg = CtdlFetchMessage(msgnum); if (msg != NULL) { + size_t newpath_len; /* Prepend our node name to the Path field whenever * sending a message to another IGnet node @@ -465,10 +468,11 @@ void network_spool_msg(long msgnum, void *userdata) { if (msg->cm_fields['P'] == NULL) { msg->cm_fields['P'] = strdoop("username"); } - newpath = mallok(strlen(msg->cm_fields['P']) + - strlen(config.c_nodename) + 2); - sprintf(newpath, "%s!%s", config.c_nodename, - msg->cm_fields['P']); + newpath_len = strlen(msg->cm_fields['P']) + + strlen(config.c_nodename) + 2; + newpath = mallok(newpath_len); + snprintf(newpath, newpath_len, "%s!%s", + config.c_nodename, msg->cm_fields['P']); phree(msg->cm_fields['P']); msg->cm_fields['P'] = newpath; @@ -523,7 +527,7 @@ void network_spool_msg(long msgnum, void *userdata) { /* Send the message */ if (send == 1) { - sprintf(filename, + snprintf(filename, sizeof filename, "./network/spoolout/%s", nptr->name); fp = fopen(filename, "ab"); @@ -705,12 +709,13 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { struct recptypes *valid = NULL; char force_room[ROOMNAMELEN]; static int serialnum = 0; + size_t size; lprintf(9, "entering network_bounce()\n"); if (msg == NULL) return; - sprintf(bouncesource, "%s@%s", BOUNCESOURCE, config.c_nodename); + snprintf(bouncesource, sizeof bouncesource, "%s@%s", BOUNCESOURCE, config.c_nodename); /* * Give it a fresh message ID @@ -718,7 +723,7 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { if (msg->cm_fields['I'] != NULL) { phree(msg->cm_fields['I']); } - sprintf(buf, "%ld.%04lx.%04x@%s", + snprintf(buf, sizeof buf, "%ld.%04lx.%04x@%s", (long)time(NULL), (long)getpid(), ++serialnum, config.c_fqdn); msg->cm_fields['I'] = strdoop(buf); @@ -766,8 +771,9 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { else { oldpath = strdoop("unknown_user"); } - msg->cm_fields['P'] = mallok(strlen(oldpath) + SIZ); - sprintf(msg->cm_fields['P'], "%s!%s", config.c_nodename, oldpath); + size = strlen(oldpath) + SIZ; + msg->cm_fields['P'] = mallok(size); + snprintf(msg->cm_fields['P'], size, "%s!%s", config.c_nodename, oldpath); phree(oldpath); /* Now submit the message */ @@ -844,9 +850,9 @@ void network_process_buffer(char *buffer, long size) { else { oldpath = strdoop("unknown_user"); } - msg->cm_fields['P'] = - mallok(strlen(oldpath) + SIZ); - sprintf(msg->cm_fields['P'], "%s!%s", + size = strlen(oldpath) + SIZ; + msg->cm_fields['P'] = mallok(size); + snprintf(msg->cm_fields['P'], size, "%s!%s", config.c_nodename, oldpath); phree(oldpath); @@ -854,7 +860,7 @@ void network_process_buffer(char *buffer, long size) { serialize_message(&sermsg, msg); /* now send it */ - sprintf(filename, + snprintf(filename, sizeof filename, "./network/spoolout/%s", msg->cm_fields['D']); fp = fopen(filename, "ab"); @@ -884,7 +890,7 @@ void network_process_buffer(char *buffer, long size) { * Check to see if we already have a copy of this message */ if (network_usetable(msg) != 0) { - sprintf(buf, + snprintf(buf, sizeof buf, "Loopzapper rejected message <%s> " "from <%s> in <%s> @ <%s>\n", ((msg->cm_fields['I']!=NULL)?(msg->cm_fields['I']):""), @@ -1027,7 +1033,7 @@ void network_do_spoolin(void) { if (dp == NULL) return; while (d = readdir(dp), d != NULL) { - sprintf(filename, "./network/spoolin/%s", d->d_name); + snprintf(filename, sizeof filename, "./network/spoolin/%s", d->d_name); network_process_file(filename); } @@ -1069,7 +1075,7 @@ void receive_spool(int sock, char *remote_nodename) { } while (bytes_received < download_len) { - sprintf(buf, "READ %ld|%ld", + snprintf(buf, sizeof buf, "READ %ld|%ld", bytes_received, ((download_len - bytes_received > IGNET_PACKET_SIZE) ? IGNET_PACKET_SIZE : (download_len - bytes_received))); @@ -1105,7 +1111,7 @@ void receive_spool(int sock, char *remote_nodename) { return; } lprintf(9, "%s\n", buf); - sprintf(buf, "mv %s ./network/spoolin/%s.%ld", + snprintf(buf, sizeof buf, "mv %s ./network/spoolin/%s.%ld", tempfilename, remote_nodename, (long) getpid()); system(buf); } @@ -1131,7 +1137,7 @@ void transmit_spool(int sock, char *remote_nodename) return; } - sprintf(sfname, "./network/spoolout/%s", remote_nodename); + snprintf(sfname, sizeof sfname, "./network/spoolout/%s", remote_nodename); fd = open(sfname, O_RDONLY); if (fd < 0) { if (errno == ENOENT) { @@ -1145,7 +1151,7 @@ void transmit_spool(int sock, char *remote_nodename) while (plen = (long) read(fd, pbuf, IGNET_PACKET_SIZE), plen > 0L) { bytes_to_write = plen; while (bytes_to_write > 0L) { - sprintf(buf, "WRIT %ld", bytes_to_write); + snprintf(buf, sizeof buf, "WRIT %ld", bytes_to_write); if (sock_puts(sock, buf) < 0) { close(fd); return; @@ -1205,7 +1211,7 @@ void network_poll_node(char *node, char *secret, char *host, char *port) { lprintf(9, ">%s\n", buf); /* Identify ourselves */ - sprintf(buf, "NETP %s|%s", config.c_nodename, secret); + snprintf(buf, sizeof buf, "NETP %s|%s", config.c_nodename, secret); lprintf(9, "<%s\n", buf); if (sock_puts(sock, buf) <0) goto bail; if (sock_gets(sock, buf) < 0) goto bail; diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index 048459a27..92a02c12b 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -450,7 +450,7 @@ void pop3_update(void) { lgetuser(&CC->usersupp, CC->curr_user); CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); - sprintf(vbuf.v_seen, "*:%ld", + snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", POP3->msgs[POP3->num_msgs-1].msgnum); CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 25082d77c..7334ca0fb 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -110,8 +110,8 @@ void smtp_greeting(void) { CtdlAllocUserData(SYM_SMTP, sizeof(struct citsmtp)); CtdlAllocUserData(SYM_SMTP_RECPS, SIZ); CtdlAllocUserData(SYM_SMTP_ROOMS, SIZ); - sprintf(SMTP_RECPS, "%s", ""); - sprintf(SMTP_ROOMS, "%s", ""); + snprintf(SMTP_RECPS, SIZ, "%s", ""); + snprintf(SMTP_ROOMS, SIZ, "%s", ""); cprintf("220 %s ESMTP Citadel/UX server ready.\r\n", config.c_fqdn); } @@ -620,7 +620,8 @@ void smtp_command_loop(void) { * Called by smtp_do_procmsg() to attempt delivery to one SMTP host * */ -void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) +void smtp_try(const char *key, const char *addr, int *status, + char *dsn, size_t n, long msgnum) { int sock = (-1); char mxhosts[1024]; @@ -646,7 +647,7 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum) msg_fp = tmpfile(); if (msg_fp == NULL) { *status = 4; - sprintf(dsn, "Error creating temporary file"); + snprintf(dsn, n, "Error creating temporary file"); return; } else { @@ -1197,7 +1198,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) { --i; --lines; lprintf(9, "SMTP: Trying <%s>\n", addr); - smtp_try(key, addr, &status, dsn, text_msgid); + smtp_try(key, addr, &status, dsn, sizeof dsn, text_msgid); if (status != 2) { if (results == NULL) { results = mallok(1024); @@ -1207,7 +1208,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) { results = reallok(results, strlen(results) + 1024); } - sprintf(&results[strlen(results)], + snprintf(&results[strlen(results)], 1024, "%s|%s|%d|%s\n", key, addr, status, dsn); } diff --git a/citadel/server_main.c b/citadel/server_main.c index bc330df66..c7b73329c 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -70,6 +70,7 @@ int main(int argc, char **argv) int drop_root_perms = 1; char *moddir; struct worker_node *wnp; + size_t size; /* specify default port name and trace file */ strcpy(tracefile, ""); @@ -170,8 +171,9 @@ int main(int argc, char **argv) * Load any server-side modules (plugins) available here. */ lprintf(7, "Initializing loadable modules\n"); - if ((moddir = malloc(strlen(bbs_home_directory) + 9)) != NULL) { - sprintf(moddir, "%s/modules", bbs_home_directory); + size = strlen(bbs_home_directory) + 9; + if ((moddir = mallok(size)) != NULL) { + snprintf(moddir, size, "%s/modules", bbs_home_directory); DLoader_Init(moddir); free(moddir); } diff --git a/citadel/tools.c b/citadel/tools.c index bb7e2a9ed..493e90b2e 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -340,7 +340,7 @@ void striplt(char *buf) /* * Return the number of occurances of character ch in string st */ -int haschar(char *st, int ch) +int haschar(const char *st, int ch) { int a, b; b = 0; diff --git a/citadel/tools.h b/citadel/tools.h index 36532f408..57d03d89c 100644 --- a/citadel/tools.h +++ b/citadel/tools.h @@ -7,7 +7,7 @@ long int extract_long (char *source, long int parmnum); void encode_base64(char *dest, char *source); int decode_base64(char *dest, char *source, size_t length); void striplt(char *); -int haschar(char *st, int ch); +int haschar(const char *st, int ch); int collapsed_strcmp(char *s1, char *s2); void remove_token(char *source, int parmnum, char separator); void fmt_date(char *buf, time_t thetime, int seconds);