All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c
@ 2025-02-17 16:21 Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] ip: handle NULL return from localtime in strxf_time in Anton Moryakov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 16:21 UTC (permalink / raw)
  To: netdev; +Cc: Anton Moryakov

Static analyzer reported:
Return value of function 'iproute_flush_cache', called at iproute.c:1732, 
is not checked. The return value is obtained from function 'open64' and possibly contains an error code.

Corrections explained:
The function iproute_flush_cache() may return an error code, which was
previously ignored. This could lead to unexpected behavior if the cache
flush fails. Added error handling to ensure the function fails gracefully
when iproute_flush_cache() returns an error.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
 ip/iproute.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index e1fe26ce..64e7d77e 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1729,7 +1729,10 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
 
 	if (filter.cloned) {
 		if (family != AF_INET6) {
-			iproute_flush_cache();
+			ret = iproute_flush_cache();
+			if(ret < 0)
+				return ret;
+				
 			if (show_stats)
 				printf("*** IPv4 routing cache is flushed.\n");
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iproute2-next] ip: handle NULL return from localtime in strxf_time in
  2025-02-17 16:21 [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c Anton Moryakov
@ 2025-02-17 16:21 ` Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] ip: remove duplicate condition in ila_csum_name2mode in Anton Moryakov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 16:21 UTC (permalink / raw)
  To: netdev; +Cc: Anton Moryakov

Static analyzer reported:
Pointer 'tp', returned from function 'localtime' at ipxfrm.c:352, may be NULL 
and is dereferenced at ipxfrm.c:354 by calling function 'strftime'.

Corrections explained:
The function localtime() may return NULL if the provided time value is
invalid. This commit adds a check for NULL and handles the error case
by copying "invalid-time" into the output buffer.
Unlikely, but may return an error

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 ip/ipxfrm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 90d25aac..9bfd96ab 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -351,7 +351,12 @@ static const char *strxf_time(__u64 time)
 		t = (long)time;
 		tp = localtime(&t);
 
-		strftime(str, sizeof(str), "%Y-%m-%d %T", tp);
+		if (!tp) {
+			/* Handle error case */
+			strcpy(str, "invalid-time");
+		} else {
+			strftime(str, sizeof(str), "%Y-%m-%d %T", tp);
+		}
 	}
 
 	return str;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iproute2-next] ip: remove duplicate condition in ila_csum_name2mode in
  2025-02-17 16:21 [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] ip: handle NULL return from localtime in strxf_time in Anton Moryakov
@ 2025-02-17 16:21 ` Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] lib: remove redundant checks in get_u64 and get_s64 Anton Moryakov
  2025-02-19 15:54 ` [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c David Ahern
  3 siblings, 0 replies; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 16:21 UTC (permalink / raw)
  To: netdev; +Cc: Anton Moryakov

Static analyzer reported:
expression is identical to previous conditio

Corrections explained:
The condition checking for "neutral-map-auto" was duplicated in the
ila_csum_name2mode function. This commit removes the redundant check
to improve code readability and maintainability.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 ip/ila_common.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/ip/ila_common.h b/ip/ila_common.h
index f99c2672..cd3524d5 100644
--- a/ip/ila_common.h
+++ b/ip/ila_common.h
@@ -31,8 +31,6 @@ static inline int ila_csum_name2mode(char *name)
 		return ILA_CSUM_NEUTRAL_MAP_AUTO;
 	else if (strcmp(name, "no-action") == 0)
 		return ILA_CSUM_NO_ACTION;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
 	else
 		return -1;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iproute2-next] lib: remove redundant checks in get_u64 and get_s64
  2025-02-17 16:21 [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] ip: handle NULL return from localtime in strxf_time in Anton Moryakov
  2025-02-17 16:21 ` [PATCH iproute2-next] ip: remove duplicate condition in ila_csum_name2mode in Anton Moryakov
@ 2025-02-17 16:21 ` Anton Moryakov
  2025-02-19 15:54 ` [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c David Ahern
  3 siblings, 0 replies; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 16:21 UTC (permalink / raw)
  To: netdev; +Cc: Anton Moryakov

Static analyzer reported:
1. if (res > 0xFFFFFFFFFFFFFFFFULL)
Expression 'res > 0xFFFFFFFFFFFFFFFFULL' is always false , which may be caused by a logical error: 
'res' has a type 'unsigned long long' with minimum value '0' and a maximum value '18446744073709551615'

2. if (res > INT64_MAX || res < INT64_MIN)
Expression 'res > INT64_MAX' is always false , which may be caused by a logical error: 'res' has a type 'long long' 
with minimum value '-9223372036854775808' and a maximum value '9223372036854775807'
Expression 'res < INT64_MIN' is always false , which may be caused by a logical error: 'res' has a type 'long long' 
with minimum value '-9223372036854775808' and a maximum value '9223372036854775807'

Corrections explained:
- Removed redundant check `res > 0xFFFFFFFFFFFFFFFFULL` in `get_u64`,
  as `res` cannot exceed this value due to its type.
- Removed redundant checks `res > INT64_MAX` and `res < INT64_MIN` in `get_s64`,
  as `res` cannot exceed the range of `long long`.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 lib/utils.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/lib/utils.c b/lib/utils.c
index be2ce0fe..706e93c3 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -304,10 +304,6 @@ int get_u64(__u64 *val, const char *arg, int base)
 	if (res == ULLONG_MAX && errno == ERANGE)
 		return -1;
 
-	/* in case ULL is 128 bits */
-	if (res > 0xFFFFFFFFFFFFFFFFULL)
-		return -1;
-
 	*val = res;
 	return 0;
 }
@@ -399,8 +395,6 @@ int get_s64(__s64 *val, const char *arg, int base)
 		return -1;
 	if ((res == LLONG_MIN || res == LLONG_MAX) && errno == ERANGE)
 		return -1;
-	if (res > INT64_MAX || res < INT64_MIN)
-		return -1;
 
 	*val = res;
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c
  2025-02-17 16:21 [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c Anton Moryakov
                   ` (2 preceding siblings ...)
  2025-02-17 16:21 ` [PATCH iproute2-next] lib: remove redundant checks in get_u64 and get_s64 Anton Moryakov
@ 2025-02-19 15:54 ` David Ahern
  3 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2025-02-19 15:54 UTC (permalink / raw)
  To: Anton Moryakov, netdev

On 2/17/25 9:21 AM, Anton Moryakov wrote:
> Static analyzer reported:
> Return value of function 'iproute_flush_cache', called at iproute.c:1732, 
> is not checked. The return value is obtained from function 'open64' and possibly contains an error code.
> 
> Corrections explained:
> The function iproute_flush_cache() may return an error code, which was
> previously ignored. This could lead to unexpected behavior if the cache
> flush fails. Added error handling to ensure the function fails gracefully
> when iproute_flush_cache() returns an error.
> 
> Triggers found by static analyzer Svace.
> 
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
> ---
>  ip/iproute.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/ip/iproute.c b/ip/iproute.c
> index e1fe26ce..64e7d77e 100644
> --- a/ip/iproute.c
> +++ b/ip/iproute.c
> @@ -1729,7 +1729,10 @@ static int iproute_flush(int family, rtnl_filter_t filter_fn)
>  
>  	if (filter.cloned) {
>  		if (family != AF_INET6) {
> -			iproute_flush_cache();
> +			ret = iproute_flush_cache();
> +			if(ret < 0)
> +				return ret;
> +				
>  			if (show_stats)
>  				printf("*** IPv4 routing cache is flushed.\n");
>  		}

applied all 4 after fixups on the first 2. This patch has style errors
(extra tabs on the newline, space between `if(`.

patch 2 did not need brackets and the comment was not useful information.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-19 15:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 16:21 [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c Anton Moryakov
2025-02-17 16:21 ` [PATCH iproute2-next] ip: handle NULL return from localtime in strxf_time in Anton Moryakov
2025-02-17 16:21 ` [PATCH iproute2-next] ip: remove duplicate condition in ila_csum_name2mode in Anton Moryakov
2025-02-17 16:21 ` [PATCH iproute2-next] lib: remove redundant checks in get_u64 and get_s64 Anton Moryakov
2025-02-19 15:54 ` [PATCH iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.