diff mbox series

[iproute2-next,06/11] nexthop: fix clang warning about timer check

Message ID 20220108204650.36185-7-sthemmin@microsoft.com (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series Clang warning fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Jan. 8, 2022, 8:46 p.m. UTC
Clang correctly flags that ipnexthop is comparing timer
with a value that it can never have.

On 64 bit platform ~0UL / 100  = 184467440737095516
and timer is u32 so max is 4294967295.

Fixes: 91676718228b ("nexthop: Add support for resilient nexthop groups")
Cc: idosch@nvidia.com
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 ip/ipnexthop.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Ido Schimmel Jan. 11, 2022, 1:31 p.m. UTC | #1
On Sat, Jan 08, 2022 at 12:46:45PM -0800, Stephen Hemminger wrote:
> diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
> index 83a5540e771c..2c65df294587 100644
> --- a/ip/ipnexthop.c
> +++ b/ip/ipnexthop.c
> @@ -31,6 +31,8 @@ enum {
>  	IPNH_FLUSH,
>  };
>  
> +#define TIMER_MAX   (~(__u32)0 / 100)
> +
>  #define RTM_NHA(h)  ((struct rtattr *)(((char *)(h)) + \
>  			NLMSG_ALIGN(sizeof(struct nhmsg))))
>  
> @@ -839,8 +841,8 @@ static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
>  			__u32 idle_timer;
>  
>  			NEXT_ARG();
> -			if (get_unsigned(&idle_timer, *argv, 0) ||
> -			    idle_timer >= ~0UL / 100)
> +			if (get_u32(&idle_timer, *argv, 0) ||
> +			    idle_timer >= TIMER_MAX)
>  				invarg("invalid idle timer value", *argv);
>  
>  			addattr32(n, maxlen, NHA_RES_GROUP_IDLE_TIMER,
> @@ -849,8 +851,8 @@ static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
>  			__u32 unbalanced_timer;
>  
>  			NEXT_ARG();
> -			if (get_unsigned(&unbalanced_timer, *argv, 0) ||
> -			    unbalanced_timer >= ~0UL / 100)
> +			if (get_u32(&unbalanced_timer, *argv, 0) ||
> +			    unbalanced_timer >= TIMER_MAX)
>  				invarg("invalid unbalanced timer value", *argv);

I believe these were already addressed by:
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=5f8bb902e14f91161f9ed214d5fc1d813af8ed88

>  
>  			addattr32(n, maxlen, NHA_RES_GROUP_UNBALANCED_TIMER,
> -- 
> 2.30.2
>
David Ahern Jan. 11, 2022, 4:01 p.m. UTC | #2
On 1/8/22 1:46 PM, Stephen Hemminger wrote:
> diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
> index 83a5540e771c..2c65df294587 100644
> --- a/ip/ipnexthop.c
> +++ b/ip/ipnexthop.c
> @@ -31,6 +31,8 @@ enum {
>  	IPNH_FLUSH,
>  };
>  
> +#define TIMER_MAX   (~(__u32)0 / 100)

UINT_MAX instead of "~(__u32)0)"
diff mbox series

Patch

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 83a5540e771c..2c65df294587 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -31,6 +31,8 @@  enum {
 	IPNH_FLUSH,
 };
 
+#define TIMER_MAX   (~(__u32)0 / 100)
+
 #define RTM_NHA(h)  ((struct rtattr *)(((char *)(h)) + \
 			NLMSG_ALIGN(sizeof(struct nhmsg))))
 
@@ -839,8 +841,8 @@  static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
 			__u32 idle_timer;
 
 			NEXT_ARG();
-			if (get_unsigned(&idle_timer, *argv, 0) ||
-			    idle_timer >= ~0UL / 100)
+			if (get_u32(&idle_timer, *argv, 0) ||
+			    idle_timer >= TIMER_MAX)
 				invarg("invalid idle timer value", *argv);
 
 			addattr32(n, maxlen, NHA_RES_GROUP_IDLE_TIMER,
@@ -849,8 +851,8 @@  static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
 			__u32 unbalanced_timer;
 
 			NEXT_ARG();
-			if (get_unsigned(&unbalanced_timer, *argv, 0) ||
-			    unbalanced_timer >= ~0UL / 100)
+			if (get_u32(&unbalanced_timer, *argv, 0) ||
+			    unbalanced_timer >= TIMER_MAX)
 				invarg("invalid unbalanced timer value", *argv);
 
 			addattr32(n, maxlen, NHA_RES_GROUP_UNBALANCED_TIMER,