diff mbox series

[iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c

Message ID 20250217162153.838113-1-ant.v.moryakov@gmail.com (mailing list archive)
State Accepted
Delegated to: David Ahern
Headers show
Series [iproute2-next] ip: check return value of iproute_flush_cache() in irpoute.c | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Anton Moryakov Feb. 17, 2025, 4:21 p.m. UTC
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(-)

Comments

David Ahern Feb. 19, 2025, 3:54 p.m. UTC | #1
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.
diff mbox series

Patch

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");
 		}