]> git.puffer.fish Git - mirror/frr.git/commitdiff
[bgpd] Fix infinite loop in community_str2com
authorPaul Jakma <paul.jakma@sun.com>
Thu, 30 Mar 2006 14:39:35 +0000 (14:39 +0000)
committerPaul Jakma <paul.jakma@sun.com>
Thu, 30 Mar 2006 14:39:35 +0000 (14:39 +0000)
2006-03-30 Paul Jakma <paul.jakma@sun.com>

* bgp_community.c: (community_gettoken) Unknown token should
  return NULL, to give a strong indication to callers that
  the token no longer can be parsed, otherwise callers looping
  on this function may have a hard time ending their loop.
  (community_str2com) While loop around community_gettoken appears
  to have been coded thinking that break statement would break
  from the while{}, hence it could never exit for unknown token
  case. Fix it to do..while, so it can use the NULL result from
  community_gettoken easily.

bgpd/ChangeLog
bgpd/bgp_community.c

index 26897f3c0d57f80324ed69a3ae4867e68bc307a2..2a442f2725c87bf587ac64a61af26ecfe99646ad 100644 (file)
@@ -1,3 +1,15 @@
+2006-03-30 Paul Jakma <paul.jakma@sun.com>
+
+       * bgp_community.c: (community_gettoken) Unknown token should
+         return NULL, to give a strong indication to callers that
+         the token no longer can be parsed, otherwise callers looping
+         on this function may have a hard time ending their loop.
+         (community_str2com) While loop around community_gettoken appears
+         to have been coded thinking that break statement would break
+         from the while{}, hence it could never exit for unknown token
+         case. Fix it to do..while, so it can use the NULL result from
+         community_gettoken easily.
+
 2006-03-22 Paul Jakma <paul.jakma@sun.com>
 
        * bgpd.c: (peer_free) release the per-peer workqueue when
index 3033db14e64ba26e29fb90c3558dbbf4fe7e1684..b419a203b74a209fa586c5bc46aed40fb6adada0 100644 (file)
@@ -520,7 +520,7 @@ community_gettoken (const char *buf, enum community_token *token,
 
       /* Unknown string. */
       *token = community_token_unknown;
-      return p;
+      return NULL;
     }
 
   /* Community value. */
@@ -538,7 +538,7 @@ community_gettoken (const char *buf, enum community_token *token,
              if (separator)
                {
                  *token = community_token_unknown;
-                 return p;
+                 return NULL;
                }
              else
                {
@@ -559,14 +559,14 @@ community_gettoken (const char *buf, enum community_token *token,
       if (! digit)
        {
          *token = community_token_unknown;
-         return p;
+         return NULL;
        }
       *val = community_high + community_low;
       *token = community_token_val;
       return p;
     }
   *token = community_token_unknown;
-  return p;
+  return NULL;
 }
 
 /* convert string to community structure */
@@ -578,8 +578,10 @@ community_str2com (const char *str)
   u_int32_t val;
   enum community_token token;
 
-  while ((str = community_gettoken (str, &token, &val))) 
+  do 
     {
+      str = community_gettoken (str, &token, &val);
+      
       switch (token)
        {
        case community_token_val:
@@ -596,7 +598,7 @@ community_str2com (const char *str)
            community_free (com);
          break;
        }
-    }
+    } while (str);
   
   if (! com)
     return NULL;