]> granicus.if.org Git - mutt/commitdiff
Fix a security problem.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 1 Jan 2002 19:58:54 +0000 (19:58 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 1 Jan 2002 19:58:54 +0000 (19:58 +0000)
rfc822.c

index 1611a1401fc32266fbec5fd146c5f4ea32158dfa..2b587418f0c4662f6c3a185f3c91fab5d0dba07c 100644 (file)
--- a/rfc822.c
+++ b/rfc822.c
 #include "rfc822.h"
 #endif
 
+#define terminate_string(a, b, c) do { if ((b) < (c)) a[(b)] = 0; else \
+       a[(c)] = 0; } while (0)
+
+#define terminate_buffer(a, b) terminate_string(a, b, sizeof (a) - 1)
+
+
 const char RFC822Specials[] = "@.,:;<>[]\\\"()";
 #define is_special(x) strchr(RFC822Specials,x)
 
@@ -227,12 +233,12 @@ parse_address (const char *s,
       return NULL;
   }
 
-  token[*tokenlen] = 0;
+  terminate_string (token, *tokenlen, tokenmax);
   addr->mailbox = safe_strdup (token);
 
   if (*commentlen && !addr->personal)
   {
-    comment[*commentlen] = 0;
+    terminate_string (comment, *commentlen, commentmax);
     addr->personal = safe_strdup (comment);
   }
 
@@ -320,9 +326,6 @@ add_addrspec (ADDRESS **top, ADDRESS **last, const char *phrase,
   *last = cur;
 }
 
-#define terminate_string(a, b) do { if (b < sizeof(a) - 1) a[b] = 0; else \
-       a[sizeof(a) - 1] = 0; } while (0)
-
 ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
 {
   const char *begin, *ps;
@@ -344,12 +347,12 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
     {
       if (phraselen)
       {
-       terminate_string (phrase, phraselen);
+       terminate_buffer (phrase, phraselen);
        add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
       }
       else if (commentlen && last && !last->personal)
       {
-       terminate_string (comment, commentlen);
+       terminate_buffer (comment, commentlen);
        last->personal = safe_strdup (comment);
       }
 
@@ -377,7 +380,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
     else if (*s == ':')
     {
       cur = rfc822_new_address ();
-      terminate_string (phrase, phraselen);
+      terminate_buffer (phrase, phraselen);
       cur->mailbox = safe_strdup (phrase);
       cur->group = 1;
 
@@ -401,12 +404,12 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
     {
       if (phraselen)
       {
-       terminate_string (phrase, phraselen);
+       terminate_buffer (phrase, phraselen);
        add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
       }
       else if (commentlen && last && !last->personal)
       {
-       terminate_string (phrase, phraselen);
+       terminate_buffer (phrase, phraselen);
        last->personal = safe_strdup (comment);
       }
 #ifdef EXACT_ADDRESS
@@ -430,7 +433,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
     }
     else if (*s == '<')
     {
-      terminate_string (phrase, phraselen);
+      terminate_buffer (phrase, phraselen);
       cur = rfc822_new_address ();
       if (phraselen)
       {
@@ -473,13 +476,13 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
   
   if (phraselen)
   {
-    terminate_string (phrase, phraselen);
-    terminate_string (comment, commentlen);
+    terminate_buffer (phrase, phraselen);
+    terminate_buffer (comment, commentlen);
     add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
   }
   else if (commentlen && last && !last->personal)
   {
-    terminate_string (comment, commentlen);
+    terminate_buffer (comment, commentlen);
     last->personal = safe_strdup (comment);
   }
 #ifdef EXACT_ADDRESS