]> Pileus Git - ~andy/fetchmail/commitdiff
Better protection against buffer overruns.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 23 Sep 1996 05:56:18 +0000 (05:56 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 23 Sep 1996 05:56:18 +0000 (05:56 -0000)
svn path=/trunk/; revision=106

driver.c
fetchmail.c
fetchmail.h
imap.c
pop2.c
pop3.c

index a707d1dab12904f3b0d54caf512b3df4de043648..b66a446f9d3f359ae0e303577d2546a3dc0916ab 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -66,7 +66,7 @@ struct method *proto;
 {
     int ok, len;
     int mboxfd;
-    char buf [POPBUFSIZE], host[HOSTLEN];
+    char buf [POPBUFSIZE+1], host[HOSTLEN+1];
     int socket;
     int first,number,count;
 
@@ -250,7 +250,7 @@ int socket;
 const char *fmt;
 va_dcl {
 
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
   va_list ap;
 
   if (protocol->tagged)
@@ -288,7 +288,7 @@ const char *fmt;
 va_dcl {
 
   int ok;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
   va_list ap;
 
   if (protocol->tagged)
@@ -332,7 +332,7 @@ const char *host;
 {
     const char *from;
     int state = 0;
-    char mycopy[POPBUFSIZE];
+    char mycopy[POPBUFSIZE+1];
 
     if (strncmp("From: ", buf, 6)
        && strncmp("To: ", buf, 4)
@@ -429,7 +429,7 @@ const char *host;
 static char *nxtaddr(hdr)
 char *hdr;
 {
-    static char        *hp, *tp, address[POPBUFSIZE];
+    static char        *hp, *tp, address[POPBUFSIZE+1];
     static     state;
 
     if (hdr)
@@ -562,8 +562,8 @@ char *pophost;
 int output;
 int rewrite;
 { 
-    char buf [MSGBUFSIZE]; 
-    char fromBuf[MSGBUFSIZE];
+    char buf [MSGBUFSIZE+1]; 
+    char fromBuf[MSGBUFSIZE+1];
     char *bufp, *headers, *unixfrom, *fromhdr, *tohdr, *cchdr, *bcchdr;
     int n, oldlen;
     int inheaders;
index 3b9dfc1cda4c774b902a1178e9b6bd297365896a..f25ca98c8c4d53f626bda5522b83897647e7a1f3 100644 (file)
@@ -139,7 +139,7 @@ char **argv;
        tmpdir = "/tmp";
     strcpy(tmpbuf, tmpdir);
     strcat(tmpbuf, "/poplock-");
-    gethostname(tmpbuf + strlen(tmpbuf), HOSTLEN);
+    gethostname(tmpbuf + strlen(tmpbuf), HOSTLEN+1);
     if ((user = getenv("USER")) != (char *)NULL)
     {
        strcat(tmpbuf, "-");
@@ -339,7 +339,7 @@ struct hostrec *queryctl;
        for (i = 0; i < sizeof(autoprobe)/sizeof(autoprobe[0]); i++)
        {
            queryctl->protocol = autoprobe[i];
-           if ((st = query_host(queryctl)) == PS_SUCCESS || st == PS_NOMAIL)
+           if ((st = query_host(queryctl)) == PS_SUCCESS || st == PS_NOMAIL || st == PS_AUTHFAIL)
                break;
        }
        queryctl->protocol = P_AUTO;
index 7bfb1921cd0e8ba46f41c97bae5a29e211dc9722..17af19c5d5304b082b875d606f21540818d7167e 100644 (file)
 
 struct hostrec
 {
-  char servername [HOSTLEN];
-  char localname [USERNAMELEN];
-  char remotename [USERNAMELEN];
-  char password [PASSWORDLEN];
-  char rpopid [PASSWORDLEN];
-  char userfolder [FOLDERLEN];
+  char servername [HOSTLEN+1];
+  char localname [USERNAMELEN+1];
+  char remotename [USERNAMELEN+1];
+  char password [PASSWORDLEN+1];
+  char rpopid [PASSWORDLEN+1];
+  char userfolder [FOLDERLEN+1];
   char remotefolder [FOLDERLEN];
-  char smtphost[HOSTLEN];
-  char mda [MDALEN];
+  char smtphost[HOSTLEN+1];
+  char mda [MDALEN+1];
   int keep;
   int protocol;
   int fetchall;
diff --git a/imap.c b/imap.c
index fa1e9551351e770027d769889dbf697eb0100341..06312d029d6958ab631817d87a37c637b24a7c55 100644 (file)
--- a/imap.c
+++ b/imap.c
@@ -42,7 +42,7 @@ char *argbuf;
 int socket;
 {
   int ok;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
   char *bufp;
   int n;
 
@@ -134,7 +134,7 @@ int number;
 int limit;
 int *lenp; 
 {
-    char buf [POPBUFSIZE];
+    char buf [POPBUFSIZE+1];
     int        num;
 
     if (limit) 
@@ -165,7 +165,7 @@ int socket;
 struct hostrec *queryctl;
 int number;
 {
-    char buf [POPBUFSIZE];
+    char buf [POPBUFSIZE+1];
 
     if (SockGets(socket, buf,sizeof(buf)) < 0)
        return(PS_SOCKET);
diff --git a/pop2.c b/pop2.c
index 26bc1ea994df1b65fd354f4de37bd43fdac0ff76..5b27e9183a273f1185392de1f1cb2ba479371b1c 100644 (file)
--- a/pop2.c
+++ b/pop2.c
@@ -311,7 +311,7 @@ int socket;
 int POP2_stateGREET (socket)
 int socket;
 {
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
  
   /* read the greeting from the server */
   if (SockGets(socket, buf, sizeof(buf)) >= 0) {
@@ -356,7 +356,7 @@ int POP2_stateNMBR (socket)
 int socket;
 {
   int number;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
 
   /* read the NMBR (#ccc) message from the server */
   if (SockGets(socket, buf, sizeof(buf)) >= 0) {
@@ -405,7 +405,7 @@ int POP2_stateSIZE (socket)
 int socket;
 {
   int msgsize;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
 
   /* read the SIZE message (=ccc) from the server */
   if (SockGets(socket, buf, sizeof(buf)) >= 0) 
@@ -463,8 +463,8 @@ int mboxfd;
 int topipe;
 {
   int i,buflen,actsize;
-  char buf [MSGBUFSIZE]; 
-  char frombuf [MSGBUFSIZE];
+  char buf [MSGBUFSIZE+1]; 
+  char frombuf [MSGBUFSIZE+1];
   char savec;
   int msgTop;
   int needFrom;
diff --git a/pop3.c b/pop3.c
index 379d38732657c074b4da9ce62981372d355dc09d..4ea41660f1a5ed9f4b7343a8661291a589265d20 100644 (file)
--- a/pop3.c
+++ b/pop3.c
@@ -47,7 +47,7 @@ char *argbuf;
 int socket;
 {
   int ok;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
   char *bufp;
 
   if (SockGets(socket, buf, sizeof(buf)) >= 0) {
@@ -86,7 +86,7 @@ int socket;
 struct hostrec *queryctl;
 char *greeting;
 {
-    char buf [POPBUFSIZE];
+    char buf [POPBUFSIZE+1];
 
 #if defined(HAVE_APOP_SUPPORT)
     /* build MD5 digest from greeting timestamp + password */
@@ -175,8 +175,8 @@ int *firstp;
   *firstp = 1;
   use_uidl = 0;
   if (!queryctl->fetchall) {
-    char buf [POPBUFSIZE];
-    char id [IDLEN];
+    char buf [POPBUFSIZE+1];
+    char id [IDLEN+1];
     int num;
 
     /* try LAST first */
@@ -282,7 +282,7 @@ int *msgcount;
 int socket;
 {
   int ok;
-  char buf [POPBUFSIZE];
+  char buf [POPBUFSIZE+1];
   int totalsize;
 
   SockPrintf(socket,"STAT\r\n");