* Realized that there was lots of similarly broken code in
authorArt Cancro <ajc@citadel.org>
Wed, 22 Aug 2001 04:18:18 +0000 (04:18 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 22 Aug 2001 04:18:18 +0000 (04:18 +0000)
  process_rfc822_addr().  Wrote two new utility functions in tools.c
  stripout() and stripallbut() and used them where appropriate.  This should
  take care of all possible infinite loops.

citadel/ChangeLog
citadel/internet_addressing.c
citadel/tools.c
citadel/tools.h

index 6b0623c5bde5defd89942fe1429e57b7ab004031..3501b4d57b40dcb15d863147f953fe9b6447cd57 100644 (file)
@@ -1,4 +1,10 @@
  $Log$
+ Revision 580.27  2001/08/22 04:18:17  ajc
+ * Realized that there was lots of similarly broken code in
+   process_rfc822_addr().  Wrote two new utility functions in tools.c
+   stripout() and stripallbut() and used them where appropriate.  This should
+   take care of all possible infinite loops.
+
  Revision 580.26  2001/08/22 03:43:11  ajc
  * internet_addressing.c: fixed a bug in process_rfc822_addr() that caused the
    server to jump into an endless loop when an e-mail address contained
@@ -2689,3 +2695,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 2a3e45d6463b72bf2cadb800999c7dfe872e9c44..f60f7a185a62d89a02ecee0547e31eb59b3593fa 100644 (file)
@@ -145,7 +145,6 @@ void unfold_rfc822_field(char *field) {
 void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
 {
        int a;
-       int lb, rb;
 
        strcpy(user, "");
        strcpy(node, config.c_fqdn);
@@ -153,15 +152,7 @@ void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
 
        /* extract full name - first, it's From minus <userid> */
        strcpy(name, rfc822);
-       lb = (-1);
-       rb = (-1);
-       for (a = 0; a < strlen(name); ++a) {
-               if (name[a] == '<') lb = a;
-               if (name[a] == '>') rb = a;
-       }
-       if ( (lb > 0) && (rb > lb) ) {
-               strcpy(&name[lb - 1], &name[rb + 1]);
-       }
+       stripout(name, '<', '>');
 
        /* strip anything to the left of a bang */
        while ((strlen(name) > 0) && (haschar(name, '!') > 0))
@@ -178,16 +169,9 @@ void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
        /* but if there are parentheses, that changes the rules... */
        if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
                strcpy(name, rfc822);
-               while ((strlen(name) > 0) && (name[0] != '(')) {
-                       strcpy(&name[0], &name[1]);
-               }
-               strcpy(&name[0], &name[1]);
-               for (a = 0; a < strlen(name); ++a) {
-                       if (name[a] == ')') {
-                               name[a] = 0;
-                       }
-               }
+               stripallbut(name, '(', ')');
        }
+
        /* but if there are a set of quotes, that supersedes everything */
        if (haschar(rfc822, 34) == 2) {
                strcpy(name, rfc822);
@@ -203,23 +187,13 @@ void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
        strcpy(user, rfc822);
 
        /* first get rid of anything in parens */
-       for (a = 0; a < strlen(user); ++a)
-               if (user[a] == '(') {
-                       do {
-                               strcpy(&user[a], &user[a + 1]);
-                       } while ((strlen(user) > 0) && (user[a] != ')'));
-                       strcpy(&user[a], &user[a + 1]);
-               }
+       stripout(user, '(', ')');
+
        /* if there's a set of angle brackets, strip it down to that */
        if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
-               while ((strlen(user) > 0) && (user[0] != '<')) {
-                       strcpy(&user[0], &user[1]);
-               }
-               strcpy(&user[0], &user[1]);
-               for (a = 0; a < strlen(user); ++a)
-                       if (user[a] == '>')
-                               user[a] = 0;
+               stripallbut(user, '<', '>');
        }
+
        /* strip anything to the left of a bang */
        while ((strlen(user) > 0) && (haschar(user, '!') > 0))
                strcpy(user, &user[1]);
@@ -237,22 +211,11 @@ void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
        strcpy(node, rfc822);
 
        /* first get rid of anything in parens */
-       for (a = 0; a < strlen(node); ++a)
-               if (node[a] == '(') {
-                       do {
-                               strcpy(&node[a], &node[a + 1]);
-                       } while ((strlen(node) > 0) && (node[a] != ')'));
-                       strcpy(&node[a], &node[a + 1]);
-               }
+       stripout(node, '(', ')');
+
        /* if there's a set of angle brackets, strip it down to that */
        if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
-               while ((strlen(node) > 0) && (node[0] != '<')) {
-                       strcpy(&node[0], &node[1]);
-               }
-               strcpy(&node[0], &node[1]);
-               for (a = 0; a < strlen(node); ++a)
-                       if (node[a] == '>')
-                               node[a] = 0;
+               stripallbut(node, '<', '>');
        }
 
        /* If no node specified, tack ours on instead */
index 3260e87d0de639197fa31925dada7c370c90372b..38a4e05974bb3e576e4e70efc37e25a4ddbe0385 100644 (file)
@@ -460,3 +460,40 @@ char *memreadline(char *start, char *buf, int maxlen)
 }
 
 
+/*
+ * Strip a boundarized substring out of a string (for example, remove
+ * parentheses and anything inside them).
+ */
+void stripout(char *str, char leftboundary, char rightboundary) {
+       int a;
+        int lb = (-1);
+        int rb = (-1);
+
+        for (a = 0; a < strlen(str); ++a) {
+                if (str[a] == leftboundary) lb = a;
+                if (str[a] == rightboundary) rb = a;
+        }
+
+        if ( (lb > 0) && (rb > lb) ) {
+                strcpy(&str[lb - 1], &str[rb + 1]);
+        }
+
+}
+
+
+/*
+ * Reduce a string down to a boundarized substring (for example, remove
+ * parentheses and anything outside them).
+ */
+void stripallbut(char *str, char leftboundary, char rightboundary) {
+       int a;
+
+       for (a = 0; a < strlen(str); ++ a) {
+               if (str[a] == leftboundary) strcpy(str, &str[a+1]);
+       }
+
+       for (a = 0; a < strlen(str); ++ a) {
+               if (str[a] == rightboundary) str[a] = 0;
+       }
+
+}
index 0ea1e16198197473f099995f73145ddaad39be64..bc3871e15a372fe640e39c1a609a76097f2e9875 100644 (file)
@@ -23,3 +23,5 @@ int strncasecmp(char *, char *, int)
 
 #define extract(dest,source,parmnum)   extract_token(dest,source,parmnum,'|')
 #define num_parms(source)              num_tokens(source, '|')
+void stripout(char *str, char leftboundary, char rightboundary);
+void stripallbut(char *str, char leftboundary, char rightboundary);