Re: [PATCH,v2] mdadm: check value returned by snprintf against errors

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

 



Dear Krzysztof,


On 16.08.19 11:06, Krzysztof Smolinski wrote:
> GCC 8 checks possible truncation during snprintf more strictly
> than GCC 7 which result in compilation errors. To fix this
> problem checking result of snprintf against errors has been added.
> 
> Signed-off-by: Krzysztof Smolinski <krzysztof.smolinski@xxxxxxxxx>
> ---
>  sysfs.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/sysfs.c b/sysfs.c
> index c3137818..2995713d 100644
> --- a/sysfs.c
> +++ b/sysfs.c
> @@ -1023,12 +1023,20 @@ int sysfs_rules_apply_check(const struct mdinfo *sra,
>  	char dname[MAX_SYSFS_PATH_LEN];
>  	char resolved_path[PATH_MAX];
>  	char resolved_dir[PATH_MAX];
> +	int result;
>  
>  	if (sra == NULL || ent == NULL)
>  		return -1;
>  
> -	snprintf(dname, MAX_SYSFS_PATH_LEN, "/sys/block/%s/md/", sra->sys_name);
> -	snprintf(fname, MAX_SYSFS_PATH_LEN, "%s/%s", dname, ent->name);
> +	result = snprintf(dname, MAX_SYSFS_PATH_LEN,
> +			  "/sys/block/%s/md/", sra->sys_name);
> +	if (result < 0 || result >= MAX_SYSFS_PATH_LEN)
> +		return -1;
> +
> +	result = snprintf(fname, MAX_SYSFS_PATH_LEN,
> +			  "%s/%s", dname, ent->name);
> +	if (result < 0 || result >= MAX_SYSFS_PATH_LEN)
> +		return -1;
>  
>  	if (realpath(fname, resolved_path) == NULL ||
>  	    realpath(dname, resolved_dir) == NULL)

Looks good to me. Thank you very much. In a separate patch, mdadm
could probably be improved to return error messages for the user.


Kind regards,

Paul

<<attachment: smime.p7s>>


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux