aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorTony Hutter <[email protected]>2018-04-04 10:16:47 -0700
committerBrian Behlendorf <[email protected]>2018-04-04 10:16:47 -0700
commit21a4f5cc867b4f166704df84985edc048caa2578 (patch)
tree18eb614a113f6a16c9ab5cd3c8247f2230b33cea /cmd
parent1724eb62debfaa48f5861660615d49a994945d94 (diff)
Fedora 28: Fix misc bounds check compiler warnings
Fix a bunch of (mostly) sprintf/snprintf truncation compiler warnings that show up on Fedora 28 (GCC 8.0.1). Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes #7361 Closes #7368
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zvol_id/zvol_id_main.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/cmd/zvol_id/zvol_id_main.c b/cmd/zvol_id/zvol_id_main.c
index 6bd5113f1..4a2d74cc2 100644
--- a/cmd/zvol_id/zvol_id_main.c
+++ b/cmd/zvol_id/zvol_id_main.c
@@ -55,11 +55,12 @@ main(int argc, char **argv)
{
int fd, error = 0;
char zvol_name[ZFS_MAX_DATASET_NAME_LEN];
- char zvol_name_part[ZFS_MAX_DATASET_NAME_LEN];
+ char *zvol_name_part = NULL;
char *dev_name;
struct stat64 statbuf;
int dev_minor, dev_part;
int i;
+ int rc;
if (argc < 2) {
printf("Usage: %s /dev/zvol_device_node\n", argv[0]);
@@ -88,11 +89,13 @@ main(int argc, char **argv)
return (errno);
}
if (dev_part > 0)
- snprintf(zvol_name_part, ZFS_MAX_DATASET_NAME_LEN,
- "%s-part%d", zvol_name, dev_part);
+ rc = asprintf(&zvol_name_part, "%s-part%d", zvol_name,
+ dev_part);
else
- snprintf(zvol_name_part, ZFS_MAX_DATASET_NAME_LEN,
- "%s", zvol_name);
+ rc = asprintf(&zvol_name_part, "%s", zvol_name);
+
+ if (rc == -1 || zvol_name_part == NULL)
+ goto error;
for (i = 0; i < strlen(zvol_name_part); i++) {
if (isblank(zvol_name_part[i]))
@@ -100,6 +103,8 @@ main(int argc, char **argv)
}
printf("%s\n", zvol_name_part);
+ free(zvol_name_part);
+error:
close(fd);
return (error);
}