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

Martin Doucha mdoucha@suse.cz
Fri Jul 28 10:17:08 CEST 2023


On 28. 07. 23 9:46, Cyril Hrubis wrote:
> 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.

The tst_brk_() gets called by the safe_*() functions deeper in the call 
tree. But tst_netdevice functions may be called from cleanup() where 
explicit return is necessary even after tst_brk_().

-- 
Martin Doucha   mdoucha@suse.cz
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic



More information about the ltp mailing list