Re: [PATCH net-next 4/4] s390/qeth: Convert sprintf/snprintf to scnprintf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 06, 2023 at 06:27:54PM +0100, Alexandra Winter wrote:
> From: Thorsten Winkler <twinkler@xxxxxxxxxxxxx>
> 
> This LWN article explains the rationale for this change
> https: //lwn.net/Articles/69419/

https://lwn.net/Articles/69419/

> Ie. snprintf() returns what *would* be the resulting length,
> while scnprintf() returns the actual length.

Ok, but in most cases in this patch the return value is not checked.
Is there any value in this change in those cases?

> Reported-by: Jules Irenge <jbi.octave@xxxxxxxxx>
> Reviewed-by: Alexandra Winkler <wintera@xxxxxxxxxxxxx>

s/Winkler/Winter/ ?

> Signed-off-by: Thorsten Winkler <twinkler@xxxxxxxxxxxxx>
> Signed-off-by: Alexandra Winter <wintera@xxxxxxxxxxxxx>

...

> diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
> index 1cf4e354693f..af4e60d2917e 100644
> --- a/drivers/s390/net/qeth_l3_main.c
> +++ b/drivers/s390/net/qeth_l3_main.c
> @@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
>  			     char *buf)
>  {
>  	if (proto == QETH_PROT_IPV4)
> -		return sprintf(buf, "%pI4", addr);
> +		return scnprintf(buf, INET_ADDRSTRLEN, "%pI4", addr);
>  	else
> -		return sprintf(buf, "%pI6", addr);
> +		return scnprintf(buf, INET6_ADDRSTRLEN, "%pI6", addr);
>  }


This seems to be the once case where the return value is not ignored.

Of the 4 callers of qeth_l3_ipaddr_to_string, two don't ignore the return
value. And I agree in those cases this change seems correct.

However, amongst other usages of the return value,
those callers also check for a return < 0 from this function.
Can that occur, in the sprintf or scnprintf case?



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux