]> Pileus Git - ~andy/fetchmail/commitdiff
Make alloca safe.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 20 Oct 1998 04:33:28 +0000 (04:33 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 20 Oct 1998 04:33:28 +0000 (04:33 -0000)
svn path=/trunk/; revision=2115

checkalias.c
driver.c
fetchmail.c
fetchmail.h
options.c
pop3.c
report.c
sink.c
unmime.c

index 5d5320f650fba26f5cbf2a63a98159bf8687d934..5e4386b6c5aaf9777bc564336dd39d4391754406 100644 (file)
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #include "mx.h"
 #include "fetchmail.h"
 
@@ -54,7 +47,7 @@ static int is_ip_alias(const char *name1,const char *name2)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_a_addr = (address_e *)alloca(sizeof( address_e));
+       xalloca(host_a_addr, address_e *, sizeof (address_e));
        memset (host_a_addr,0, sizeof (address_e));
        host_a_addr->next = dummy_addr;
        (void) memcpy(&host_a_addr->address, *p, sizeof (in.s_addr));
@@ -68,7 +61,7 @@ static int is_ip_alias(const char *name1,const char *name2)
     {
        struct in_addr in;
        (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
-       host_b_addr = (address_e *)alloca(sizeof( address_e));
+       xalloca(host_b_addr, address_e *, sizeof (address_e));
        memset (host_b_addr,0, sizeof (address_e));
        host_b_addr->next = dummy_addr;
        (void) memcpy(&host_b_addr->address, *p, sizeof (in.s_addr));
index fe709197aeb7e496fa8c212ddee1db1a56931e6f..25e2c819f83f4fc1cc03b34d73b71994873734c3 100644 (file)
--- a/driver.c
+++ b/driver.c
 #else
 #include  <varargs.h>
 #endif
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #if defined(HAVE_SYS_ITIMER_H)
 #include <sys/itimer.h>
 #endif
@@ -977,7 +970,7 @@ int num;            /* index of message */
                if (idp->val.status.mark == XMIT_ANTISPAM)
                    errlen += strlen(idp->id) + 2;
 
-           errmsg = alloca(errlen+3);
+           xalloca(errmsg, char *, errlen+3);
            (void) strcpy(errmsg, errhd);
            for (idp = xmit_names; idp; idp = idp->next)
                if (idp->val.status.mark == XMIT_ANTISPAM)
@@ -1116,7 +1109,7 @@ const char *canonical;    /* server name */
     Key_schedule schedule;
     int rem;
   
-    ticket = ((KTEXT) (alloca (sizeof (KTEXT_ST))));
+    xalloca(ticket, KTEXT, sizeof (KTEXT_ST));
     rem = (krb_sendauth (0L, socket, ticket, "pop",
                         canonical,
                         ((char *) (krb_realmofhost (canonical))),
@@ -1552,7 +1545,7 @@ const struct method *proto;       /* protocol method table */
                {
                    int i;
 
-                   msgsizes = (int *)alloca(sizeof(int) * count);
+                   xalloca(msgsizes, int *, sizeof(int) * count);
                    for (i = 0; i < count; i++)
                        msgsizes[i] = -1;
 
index 9e4d9240ec333cf03fe69c16e483f320a889633e..b738cf9d3e4ec10214c131115865a9f6b1b2c74b 100644 (file)
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
 #endif
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #include <string.h>
 #include <signal.h>
 #if defined(HAVE_SYSLOG)
@@ -210,7 +203,7 @@ int main (int argc, char **argv)
 
     /* set up to do lock protocol */
 #define        FETCHMAIL_PIDFILE       "fetchmail.pid"
-    tmpbuf = alloca(strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
+    xalloca(tmpbuf, char *, strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
     if (!getuid())
        sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
     else {
@@ -352,7 +345,7 @@ int main (int argc, char **argv)
     }
 
     /* parse the ~/.netrc file (if present) for future password lookups. */
-    netrc_file = (char *) alloca (strlen (home) + 8);
+    xalloca(netrc_file, char *, strlen (home) + 8);
     strcpy (netrc_file, home);
     strcat (netrc_file, "/.netrc");
     netrc_list = parse_netrc(netrc_file);
@@ -404,7 +397,7 @@ int main (int argc, char **argv)
                 && !ctl->password)
            {
 #define        PASSWORD_PROMPT "Enter password for %s@%s: "
-               tmpbuf = alloca(strlen(PASSWORD_PROMPT) +
+               xalloca(tmpbuf, char *, strlen(PASSWORD_PROMPT) +
                                        strlen(ctl->remotename) +
                                        strlen(ctl->server.pollname) + 1);
                (void) sprintf(tmpbuf, PASSWORD_PROMPT,
@@ -1494,6 +1487,10 @@ void dump_params (struct runctl *runp, struct query *querylist, flag implicit)
                    for (idp = ctl->oldsaved; idp; idp = idp->next)
                        fprintf(stderr, "\t%s\n", idp->id);
            }
+
+       if (ctl->properties)
+           printf("  Pass-through properties \"%s\".\n",
+                  visbuf(ctl->properties));
     }
 }
 
index 18de9f6c70d63d97bd1d4b3d608619ff543ce79d..f5fb1d419e834f69ec5f7028a9e66654336ab5e4 100644 (file)
@@ -397,6 +397,14 @@ int interface_approve(struct hostdata *);
 XMALLOCTYPE *xmalloc(int);
 XMALLOCTYPE *xrealloc(XMALLOCTYPE *, int);
 char *xstrdup(const char *);
+#if defined(HAVE_ALLOCA_H)
+#include <alloca.h>
+#else
+#ifdef _AIX
+ #pragma alloca
+#endif
+#endif
+#define        xalloca(ptr, t, n)      if (!(ptr = (t) alloca(n))) error(PS_UNDEFINED, 0, "alloca failed")
 
 /* protocol driver and methods */
 int do_protocol(struct query *, const struct method *);
index 4ac3813c2b63be9e15b99eb0ec75fe2ae94546ad..da8df81c4f332546c2127767e7396667e15f06df 100644 (file)
--- a/options.c
+++ b/options.c
@@ -7,13 +7,6 @@
 #include "config.h"
 
 #include <stdio.h>
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #include <pwd.h>
 #include <string.h>
 #include <errno.h>
@@ -418,7 +411,7 @@ struct query *ctl;  /* option record to be initialized */
            break;
        case 'r':
        case LA_FOLDER:
-           buf = alloca(strlen(optarg));
+           xalloca(buf, char *, strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
@@ -428,7 +421,7 @@ struct query *ctl;  /* option record to be initialized */
            break;
        case 'S':
        case LA_SMTPHOST:
-           buf = alloca(strlen(optarg));
+           xalloca(buf, char *, strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
@@ -443,7 +436,7 @@ struct query *ctl;  /* option record to be initialized */
            break;
        case 'Z':
        case LA_ANTISPAM:
-           buf = alloca(strlen(optarg));
+           xalloca(buf, char *, strlen(optarg));
            strcpy(buf, optarg);
            cp = strtok(buf, ",");
            do {
diff --git a/pop3.c b/pop3.c
index 7238e345034eb0e01363ca5df7e96324932b7ae9..11c1f7a051fa11b4816e3926f742b052421687d0 100644 (file)
--- a/pop3.c
+++ b/pop3.c
@@ -7,13 +7,6 @@
 #include  "config.h"
 #ifdef POP3_ENABLE
 #include  <stdio.h>
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #include  <string.h>
 #include  <ctype.h>
 #if defined(HAVE_UNISTD_H)
@@ -225,7 +218,7 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
            *++end = '\0';
 
        /* copy timestamp and password into digestion buffer */
-       msg = (char *)alloca((end-start+1) + strlen(ctl->password) + 1);
+       xalloca(msg, char *, (end-start+1) + strlen(ctl->password) + 1);
        strcpy(msg,start);
        strcat(msg,ctl->password);
 
index 319acba58e322d88a2bfee6c2b83e1042153f974..d2f123488bfb2f606698dc76b6bfb0d0b28360c7 100644 (file)
--- a/report.c
+++ b/report.c
@@ -31,13 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #if defined(HAVE_SYSLOG)
 #include <syslog.h>
 #endif
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 
 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC || HAVE_STDARG_H
 # if HAVE_STDARG_H
@@ -159,7 +152,9 @@ error (status, errnum, message, va_alist)
 
       if (errnum > 0)
         {
-         char *msg = alloca (strlen (message) + 5);
+         char *msg;
+         
+         xalloca(msg, char *, strlen (message) + 5);
 
          strcpy (msg, message);
          strcat (msg, ": %m");
diff --git a/sink.c b/sink.c
index 8b372d36328d1334e91c2f5d5eb837c77918e0f6..90af32edb439fe32663f9bef3eca9d75a2330761 100644 (file)
--- a/sink.c
+++ b/sink.c
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
 #endif
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 
 #include  "fetchmail.h"
 #include  "socket.h"
@@ -96,13 +89,15 @@ static int smtp_open(struct query *ctl)
        set_timeout(ctl->server.timeout);
        for (idp = ctl->smtphunt; idp; idp = idp->next)
        {
-           char        *cp, *parsed_host = alloca(strlen(idp->id) + 1);
+           char        *cp, *parsed_host;
 #ifdef INET6 
            char        *portnum = SMTP_PORT;
 #else
            int         portnum = SMTP_PORT;
 #endif /* INET6 */
 
+           xalloca(parsed_host, char *, strlen(idp->id) + 1);
+
            ctl->smtphost = idp->id;  /* remember last host tried. */
 
            strcpy(parsed_host, idp->id);
index 30eff6d49c0aaeab7b244cfe82a18e9c617d5f25..2acc3f74e2473a0bcf7db70975c32054f297c93d 100644 (file)
--- a/unmime.c
+++ b/unmime.c
 #include "config.h"
 #include <string.h>
 #include <stdlib.h>
-#if defined(HAVE_ALLOCA_H)
-#include <alloca.h>
-#else
-#ifdef _AIX
- #pragma alloca
-#endif
-#endif
 #include <ctype.h>
 #include "fetchmail.h"
 
@@ -371,7 +364,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
       XferEncOfs = NxtHdr;
       p = nxtaddr(NxtHdr);
       if (p != NULL) {
-       XferEnc = (char *)alloca(strlen(p) + 1);
+       xalloca(XferEnc, char *, strlen(p) + 1);
        strcpy(XferEnc, p);
        HdrsFound++;
       }
@@ -402,7 +395,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
       } while ( (p != NULL) && ((*(p+1) == '\t') || (*(p+1) == ' ')) );
       if (p == NULL) p = NxtHdr + strlen(NxtHdr);
 
-      CntType = (char *)alloca(p-NxtHdr+2);
+      xalloca(CntType, char *, p-NxtHdr+2);
       strncpy(CntType, NxtHdr, (p-NxtHdr));
       *(CntType+(p-NxtHdr)) = '\0';
       HdrsFound++;
@@ -410,7 +403,7 @@ int MimeBodyType(unsigned char *hdrs, int WantDecode)
     else if (strncasecmp("MIME-Version:", NxtHdr, 13) == 0) {
       p = nxtaddr(NxtHdr);
       if (p != NULL) {
-       MimeVer = (char *)alloca(strlen(p) + 1);
+       xalloca(MimeVer, char *, strlen(p) + 1);
        strcpy(MimeVer, p);
        HdrsFound++;
       }