This patch fixes the following [-Werror=format-truncation=] errors
detected by gcc 12:
liblnetconfig.c: In function 'open_sysfs_file':
liblnetconfig.c:106:49: error: '%s' directive output may be truncated
writing up to 127 bytes into a region of size between 1 and 128
[-Werror=format-truncation=]
106 | snprintf(filename, sizeof(filename), "%s%s",
| ^~
lfs_project.c: In function 'lfs_project_handle_dir':
lfs_project.c:324:50: error: '%s' directive output may be truncated
writing up to 255 bytes into a region of size between 1 and 4095
[-Werror=format-truncation=]
324 | snprintf(fullname, PATH_MAX, "%s/%s", pathname,
| ^~
statx.c: In function 'do_dir_list':
statx.c:1427:58: error: '%s' directive output may be truncated
writing up to 255 bytes into a region of size between 1 and 4095
[-Werror=format-truncation=]
1427 | snprintf(fullname, PATH_MAX, "%s/%s",
| ^~
Change-Id: I514a1022d879f8b7af89f6ded68e9b453cd11408
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51765
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
{
int fd;
char filename[LNET_MAX_STR_LEN];
+ size_t size = sizeof(filename);
+ int namelen;
- if (strlen(path) + strlen(attr) >= LNET_MAX_STR_LEN)
- return -1;
-
- snprintf(filename, sizeof(filename), "%s%s",
- path, attr);
+ namelen = snprintf(filename, size, "%s%s", path, attr);
+ if (namelen >= size)
+ filename[size - 1] = '\0';
fd = open(filename, mode);
DIR *dir;
struct dirent *ent;
char fullname[PATH_MAX];
+ size_t size = sizeof(fullname);
+ int namelen;
int rc = 0;
dir = opendir(dirname);
rc = -ENAMETOOLONG;
continue;
}
- snprintf(fullname, PATH_MAX, "%s/%s",
- dirname, ent->d_name);
+ namelen = snprintf(fullname, size, "%s/%s",
+ dirname, ent->d_name);
+ if (namelen >= size)
+ fullname[size - 1] = '\0';
+
ret = do_statx(fullname, request_mask, flags);
if (!ret)
putchar('\n');
struct project_handle_control *))
{
char fullname[PATH_MAX];
+ size_t size = sizeof(fullname);
+ int namelen;
struct dirent *ent;
DIR *dir;
int ret = 0;
progname, pathname, ent->d_name);
continue;
}
- snprintf(fullname, PATH_MAX, "%s/%s", pathname,
- ent->d_name);
+ namelen = snprintf(fullname, size, "%s/%s",
+ pathname, ent->d_name);
+ if (namelen >= size)
+ fullname[size - 1] = '\0';
rc = func(fullname, phc);
if (rc && !ret)