diff options
author | Andrew Certain <certain@amazon.com> | 2012-12-04 12:54:18 -0800 |
---|---|---|
committer | Scott Feldman <sfeldma@cumulusnetworks.com> | 2013-01-07 09:59:49 -0800 |
commit | fbc043a847149499436fe4083b6384bde43fe578 (patch) | |
tree | 17b90e2e2b22e91eb670ce0b0102047ac0862e16 | |
parent | 1a61ad1011c498c4ae66cc145db673e53ef02962 (diff) |
ospfd: Fixed signed/unsigned masking of negative metrics
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>
-rw-r--r-- | ospfd/ospf_routemap.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index adf81583..d0ebce66 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -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; |