diff options
author | Krzysztof Smolinski <krzysztof.smolinski@intel.com> | 2019-08-16 11:06:17 +0200 |
---|---|---|
committer | Jes Sorensen <jsorensen@fb.com> | 2019-08-16 16:06:50 +0200 |
commit | fd5b09c9a9107f0393ce194c4aac6e7b8f163e85 (patch) | |
tree | 668acaccc0b9c13398027db5a2c68a8b3e57ae99 /sysfs.c | |
parent | imsm: close removed drive fd. (diff) | |
download | mdadm-fd5b09c9a9107f0393ce194c4aac6e7b8f163e85.tar.xz mdadm-fd5b09c9a9107f0393ce194c4aac6e7b8f163e85.zip |
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>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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) |