This patch fixes the following -Werror=stringop-truncation warning:
In function 'hsm_scan_item_alloc',
inlined from 'hsm_scan_handle_dir' at libhsm_scanner.c:124:10:
libhsm_scanner.c:64:9: error: 'strncpy' output may be truncated
copying 4096 bytes from a string of length 4351 [-Werror=stringop-truncation]
64 | strncpy(item->hsi_pathname, pathname, sizeof(item->hsi_pathname));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'hsm_scan_item_alloc',
inlined from 'hsm_scan_process' at libhsm_scanner.c:165:7:
libhsm_scanner.c:64:9: error: 'strncpy' specified bound 4096 equals
destination size [-Werror=stringop-truncation]
64 | strncpy(item->hsi_pathname, pathname, sizeof(item->hsi_pathname));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test-Parameters: trivial testlist=sanity-pcc
Change-Id: I74c6c1de82f18ad2a652034b5952d55d44032b89
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/46286
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
struct hsm_scan_item *item;
int rc;
+ if (strlen(pathname) >= PATH_MAX) {
+ rc = -ENAMETOOLONG;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "pathname is too long: %s\n", pathname);
+ return rc;
+ }
+
item = malloc(sizeof(struct hsm_scan_item));
if (item == NULL) {
rc = -ENOMEM;
}
item->hsi_depth = depth;
- strncpy(item->hsi_pathname, pathname, sizeof(item->hsi_pathname));
+ strncpy(item->hsi_pathname, pathname, sizeof(item->hsi_pathname) - 1);
list_add_tail(&item->hsi_item, head);
return 0;
filename = basename(path_copy);
state->pccs_namelen = strlen(filename) + 1;
- strncpy(state->pccs_path, filename, sizeof(state->pccs_path));
+ strncpy(state->pccs_path, filename, sizeof(state->pccs_path) - 1);
rc = llapi_pcc_state_get_fd(fd, state);
if (rc != 0) {