[LTP] [PATCH 1/3] tst_netdevice: Add missing rtnetlink context allocation checks

Cyril Hrubis chrubis@suse.cz
Fri Jul 28 09:46:51 CEST 2023


Hi!
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>  lib/tst_netdevice.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lib/tst_netdevice.c b/lib/tst_netdevice.c
> index 4a0442932..a57f506e9 100644
> --- a/lib/tst_netdevice.c
> +++ b/lib/tst_netdevice.c
> @@ -332,6 +332,9 @@ static int change_ns(const char *file, const int lineno, const char *ifname,
>  
>  	ctx = create_request(file, lineno, RTM_NEWLINK, 0, &info, sizeof(info));
>  
> +	if (!ctx)
> +		return 0;
> +
>  	if (!tst_rtnl_add_attr_string(file, lineno, ctx, IFLA_IFNAME, ifname)) {
>  		tst_rtnl_destroy_context(file, lineno, ctx);
>  		return 0;
> @@ -411,6 +414,9 @@ static int modify_route(const char *file, const int lineno, unsigned int action,
>  
>  	ctx = create_request(file, lineno, action, flags, &info, sizeof(info));
>  
> +	if (!ctx)
> +		return 0;
> +
>  	if (srcaddr && !tst_rtnl_add_attr(file, lineno, ctx, RTA_SRC, srcaddr,
>  		srclen)) {
>  		tst_rtnl_destroy_context(file, lineno, ctx);

Shouldn't we tst_brk_() in these cases? This function is a base for
NETDEV_CHANGE_NS_*() which is used as a safe macro without checking it's
return value.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list