mdadm: check value returned by snprintf against errors

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@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Krzysztof Smolinski 2019-08-16 11:06:17 +02:00 committed by Jes Sorensen
parent 91c97c5432
commit fd5b09c9a9
1 changed files with 10 additions and 2 deletions

12
sysfs.c
View File

@ -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)