]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospfd: Fixed signed/unsigned masking of negative metrics
authorAndrew Certain <certain@amazon.com>
Tue, 4 Dec 2012 20:54:18 +0000 (12:54 -0800)
committerScott Feldman <sfeldma@cumulusnetworks.com>
Mon, 7 Jan 2013 17:59:49 +0000 (09:59 -0800)
In the original code, negative metrics would be converted successfully by
atoi() and then converted to an unsigned int that would always compare
successfully against >= 0, leaving a large positive metric in the route map.

Signed-off-by: Scott Feldman <sfeldma@cumulusnetworks.com>
ospfd/ospf_routemap.c

index adf8158395c8d848128176465dad04be2d74a41d..d0ebce66ee3b71e368f42d24f53db076c39ae48e 100644 (file)
@@ -443,12 +443,16 @@ static void *
 route_set_metric_compile (const char *arg)
 {
   u_int32_t *metric;
+  int32_t ret;
 
   metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
-  *metric = atoi (arg);
+  ret = atoi (arg);
 
-  if (*metric >= 0)
-    return metric;
+  if (ret >= 0)
+    {
+      *metric = (u_int32_t)ret;
+      return metric;
+    }
 
   XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
   return NULL;