diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | driver.c | 29 | ||||
-rw-r--r-- | fetchmail.c | 2 | ||||
-rw-r--r-- | fetchmail.h | 2 | ||||
-rw-r--r-- | imap.c | 3 | ||||
-rw-r--r-- | lock.c | 1 | ||||
-rw-r--r-- | sink.c | 32 | ||||
-rw-r--r-- | smtp.c | 16 | ||||
-rw-r--r-- | socket.c | 7 | ||||
-rw-r--r-- | socket.h | 5 | ||||
-rw-r--r-- | transact.c | 52 |
11 files changed, 121 insertions, 30 deletions
@@ -2,6 +2,8 @@ (The `lines' figures total .c, .h, .l, and .y files under version control.) +* HMH's snprintf/strncat cleanup patch. + fetchmail-5.8.8 (Wed Jun 20 17:22:26 EDT 2001), 20782 lines: * Fix bug that prevented messages from being marked oversized unless -v was on. @@ -40,6 +40,7 @@ #endif /* KERBEROS_V4 */ #include "i18n.h" +#include "socket.h" #include "fetchmail.h" #include "tunable.h" @@ -333,7 +334,12 @@ static void mark_oversized(int num, struct query *ctl, int *msgsizes) int cnt; /* convert sz to string */ - sprintf(size, "%d", msgsizes[num-1]); +#ifdef HAVE_SNPRINTF + snprintf(size, sizeof(size), +#else + sprintf(size, +#endif /* HAVE_SNPRINTF */ + "%d", msgsizes[num-1]); /* build a list of skipped messages * val.id = size of msg (string cnvt) @@ -831,7 +837,12 @@ const int maxfetch; /* maximum number of messages to fetch */ else if (h_errno == TRY_AGAIN) strcpy(errbuf, _("temporary name server error.")); else - sprintf(errbuf, _("unknown DNS error %d."), h_errno); +#ifdef HAVE_SNPRINTF + snprintf(errbuf, sizeof(errbuf), +#else + sprintf(errbuf, +#endif /* HAVE_SNPRINTF */ + _("unknown DNS error %d."), h_errno); } else #endif /* HAVE_RES_SEARCH */ @@ -1065,10 +1076,20 @@ is restored.")); /* show user how many messages we downloaded */ if (idp->id) - (void) sprintf(buf, _("%s at %s (folder %s)"), +#ifdef HAVE_SNPRINTF + (void) snprintf(buf, sizeof(buf), +#else + (void) sprintf(buf, +#endif /* HAVE_SNPRINTF */ + _("%s at %s (folder %s)"), ctl->remotename, ctl->server.truename, idp->id); else - (void) sprintf(buf, _("%s at %s"), +#ifdef HAVE_SNPRINTF + (void) snprintf(buf, sizeof(buf), +#else + (void) sprintf(buf, +#endif /* HAVE_SNPRINTF */ + _("%s at %s"), ctl->remotename, ctl->server.truename); if (outlevel > O_SILENT) { diff --git a/fetchmail.c b/fetchmail.c index 6990b223..4e405d35 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -130,7 +130,7 @@ static char *timestamp (void) int main(int argc, char **argv) { - int st, bkgd = FALSE; + int bkgd = FALSE; int parsestatus, implicitmode = FALSE; struct query *ctl; netrc_entry *netrc_list; diff --git a/fetchmail.h b/fetchmail.h index fe3eb320..0c69349d 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -431,6 +431,7 @@ extern struct msgblk msgblk; void lock_setup(void), lock_assert(void); void lock_or_die(void), lock_release(void); int lock_state(void); +void lock_dispose(void); /* use these to track what was happening when the nonresponse timer fired */ #define GENERAL_WAIT 0 /* unknown wait type */ @@ -551,6 +552,7 @@ int doPOP2 (struct query *); int doPOP3 (struct query *); int doIMAP (struct query *); int doETRN (struct query *); +int doODMR (struct query *); /* authentication functions */ int do_cram_md5(int sock, char *command, struct query *ctl); @@ -376,7 +376,7 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) #ifdef NTLM_ENABLE if ((ctl->server.authenticate == A_ANY || ctl->server.authenticate == A_NTLM) - && strstr (capabilities, "AUTH=NTLM")) + && strstr (capabilities, "AUTH=NTLM")) { if ((ok = do_imap_ntlm(sock, ctl))) { /* SASL cancellation of authentication */ @@ -386,6 +386,7 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) } else return(ok); + } #else if (ctl->server.authenticate == A_NTLM) { @@ -16,6 +16,7 @@ #include <unistd.h> #endif #include <fcntl.h> +#include <signal.h> #include "fetchmail.h" #include "i18n.h" @@ -293,7 +293,11 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg, return(FALSE); /* our first duty is to keep the sacred foo counters turning... */ - sprintf(boundary, +#ifdef HAVE_SNPRINTF + snprintf(boundary, sizeof(boundary), +#else + sprintf(boundary, +#endif /* HAVE_SNPRINTF */ "foo-mani-padme-hum-%d-%d-%ld", (int)getpid(), (int)getppid(), time((time_t *)NULL)); @@ -613,14 +617,24 @@ int open_sink(struct query *ctl, struct msgblk *msg, */ if (!msg->return_path[0]) { - sprintf(addr, "%s@%s", ctl->remotename, ctl->server.truename); +#ifdef HAVE_SNPRINTF + snprintf(addr, sizeof(addr), +#else + sprintf(addr, +#endif /* HAVE_SNPRINTF */ + "%s@%s", ctl->remotename, ctl->server.truename); ap = addr; } else if (strchr(msg->return_path, '@')) ap = msg->return_path; else /* in case Return-Path existed but was local */ { - sprintf(addr, "%s@%s", msg->return_path, ctl->server.truename); +#ifdef HAVE_SNPRINTF + snprintf(addr, sizeof(addr), +#else + sprintf(addr, +#endif /* HAVE_SNPRINTF */ + "%s@%s", msg->return_path, ctl->server.truename); ap = addr; } @@ -660,7 +674,6 @@ int open_sink(struct query *ctl, struct msgblk *msg, else { char errbuf[POPBUFSIZE]; - int res; #ifdef __UNUSED__ /* @@ -675,13 +688,14 @@ int open_sink(struct query *ctl, struct msgblk *msg, * also as the body is discarded after calling * RSET! */ + int res; if ((res = handle_smtp_report(ctl, msg))==PS_REFUSED) return(PS_REFUSED); #endif /* __UNUSED__ */ - strcpy(errbuf, idp->id); - strcat(errbuf, ": "); - strcat(errbuf, smtp_response); + strncpy(errbuf, idp->id, sizeof(errbuf)); + strncat(errbuf, ": ", sizeof(errbuf)); + strncat(errbuf, smtp_response, sizeof(errbuf)); xalloca(from_responses[*bad_addresses], char *, @@ -710,7 +724,7 @@ int open_sink(struct query *ctl, struct msgblk *msg, if (!(*good_addresses)) { if (strchr(run.postmaster, '@')) - strcpy(addr, run.postmaster); + strncpy(addr, run.postmaster, sizeof(addr)); else { #ifdef HAVE_SNPRINTF @@ -1167,7 +1181,7 @@ va_dcl #endif va_end(ap); - strcat(buf, "\r\n"); + strncat(buf, "\r\n", sizeof(buf)); stuffline(ctl, buf); } @@ -97,11 +97,21 @@ int SMTP_from(int sock, const char *from, const char *opts) char buf[MSGBUFSIZE]; if (strchr(from, '<')) - sprintf(buf, "MAIL FROM: %s", from); +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "MAIL FROM: %s", from); else - sprintf(buf, "MAIL FROM:<%s>", from); +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "MAIL FROM:<%s>", from); if (opts) - strcat(buf, opts); + strncat(buf, opts, sizeof(buf)); SockPrintf(sock,"%s\r\n", buf); if (outlevel >= O_MONITOR) report(stdout, "%cMTP> %s\n", smtp_mode, buf); @@ -325,7 +325,12 @@ int SockOpen(const char *host, int clientPort, const char *options, #ifdef HAVE_SOCKETPAIR if (plugin) { char buf[10]; - sprintf(buf,"%d",clientPort); +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), /* Yeah, paranoic. So what? :P */ +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "%d",clientPort); return handle_plugin(host,buf,plugin); } #endif /* HAVE_SOCKETPAIR */ @@ -58,6 +58,11 @@ additional clean-up if necessary. */ int SockClose(int sock); +/* +FIXME: document this +*/ +int UnixOpen(const char *path); + #if SSL_ENABLE int SSLOpen(int sock, char *mycert, char *mykey, char *myproto, int certck, char *certpath, char *fingerprint, char *servercname, char *label); @@ -10,6 +10,7 @@ #include "config.h" #include <stdio.h> #include <string.h> +#include <ctype.h> /* isspace() */ #ifdef HAVE_MEMORY_H #include <memory.h> #endif /* HAVE_MEMORY_H */ @@ -1014,14 +1015,24 @@ int readheaders(int sock, { /* utter any per-message Received information we need here */ if (ctl->server.trueaddr) { - sprintf(buf, "Received: from %s [%u.%u.%u.%u]\r\n", +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "Received: from %s [%u.%u.%u.%u]\r\n", ctl->server.truename, (unsigned char)ctl->server.trueaddr[0], (unsigned char)ctl->server.trueaddr[1], (unsigned char)ctl->server.trueaddr[2], (unsigned char)ctl->server.trueaddr[3]); } else { - sprintf(buf, "Received: from %s\r\n", ctl->server.truename); +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "Received: from %s\r\n", ctl->server.truename); } n = stuffline(ctl, buf); if (n != -1) @@ -1030,7 +1041,12 @@ int readheaders(int sock, * This header is technically invalid under RFC822. * POP3, IMAP, etc. are not legal mail-parameter values. */ - sprintf(buf, "\tby %s with %s (fetchmail-%s", +#ifdef HAVE_SNPRINTF + snprintf(buf, sizeof(buf), +#else + sprintf(buf, +#endif /* HAVE_SNPRINTF */ + "\tby %s with %s (fetchmail-%s", fetchmailhost, protocol->name, VERSION); @@ -1040,14 +1056,18 @@ int readheaders(int sock, ctl->server.pollname, ctl->remotename); } - strcat(buf, ")\r\n"); + strncat(buf, ")\r\n", sizeof(buf)); n = stuffline(ctl, buf); if (n != -1) { buf[0] = '\t'; if (good_addresses == 0) { - sprintf(buf+1, +#ifdef HAVE_SNPRINTF + snprintf(buf+1, sizeof(buf)-1, +#else + sprintf(buf+1, +#endif /* HAVE_SNPRINTF */ "for %s@%s (by default); ", user, ctl->destaddr); } @@ -1057,22 +1077,32 @@ int readheaders(int sock, if (idp->val.status.mark == XMIT_ACCEPT) break; /* only report first address */ if (strchr(idp->id, '@')) - sprintf(buf+1, "for %s", idp->id); +#ifdef HAVE_SNPRINTF + snprintf(buf+1, sizeof(buf)-1, +#else + sprintf(buf+1, +#endif /* HAVE_SNPRINTF */ + "for %s", idp->id); else /* * This could be a bit misleading, as destaddr is * the forwarding host rather than the actual * destination. Most of the time they coincide. */ - sprintf(buf+1, "for %s@%s", idp->id, ctl->destaddr); +#ifdef HAVE_SNPRINTF + snprintf(buf+1, sizeof(buf)-1, +#else + sprintf(buf+1, +#endif /* HAVE_SNPRINTF */ + "for %s@%s", idp->id, ctl->destaddr); sprintf(buf+strlen(buf), " (%s); ", MULTIDROP(ctl) ? "multi-drop" : "single-drop"); } else buf[1] = '\0'; - strcat(buf, rfc822timestamp()); - strcat(buf, "\r\n"); + strncat(buf, rfc822timestamp(), sizeof(buf)); + strncat(buf, "\r\n", sizeof(buf)); n = stuffline(ctl, buf); } } @@ -1307,7 +1337,7 @@ va_dcl #endif va_end(ap); - strcat(buf, "\r\n"); + strncat(buf, "\r\n", sizeof(buf)); SockWrite(sock, buf, strlen(buf)); if (outlevel >= O_MONITOR) @@ -1393,7 +1423,7 @@ va_dcl #endif va_end(ap); - strcat(buf, "\r\n"); + strncat(buf, "\r\n", sizeof(buf)); SockWrite(sock, buf, strlen(buf)); if (outlevel >= O_MONITOR) |