summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorTony Hutter <[email protected]>2018-04-04 10:16:47 -0700
committerTony Hutter <[email protected]>2018-05-07 17:19:57 -0700
commitf5ecab3aef3db6744f135daf8104dbb1880cc1eb (patch)
tree2e62d5e1f820db62af6f9f12fef8931a58689798 /cmd
parentfd01167ffd9b5d4634bab503e0584e6756bb8ef8 (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/zpios/zpios_main.c9
-rw-r--r--cmd/zvol_id/zvol_id_main.c15
2 files changed, 15 insertions, 9 deletions
diff --git a/cmd/zpios/zpios_main.c b/cmd/zpios/zpios_main.c
index 01f2ce197..4be26d64f 100644
--- a/cmd/zpios/zpios_main.c
+++ b/cmd/zpios/zpios_main.c
@@ -525,10 +525,11 @@ run_one(cmd_args_t *args, uint32_t id, uint32_t T, uint32_t N,
memset(cmd, 0, cmd_size);
cmd->cmd_magic = ZPIOS_CMD_MAGIC;
- strncpy(cmd->cmd_pool, args->pool, ZPIOS_NAME_SIZE - 1);
- strncpy(cmd->cmd_pre, args->pre, ZPIOS_PATH_SIZE - 1);
- strncpy(cmd->cmd_post, args->post, ZPIOS_PATH_SIZE - 1);
- strncpy(cmd->cmd_log, args->log, ZPIOS_PATH_SIZE - 1);
+ snprintf(cmd->cmd_pool, sizeof (cmd->cmd_pool), "%s", args->pool);
+ snprintf(cmd->cmd_pre, sizeof (cmd->cmd_pre), "%s", args->pre);
+ snprintf(cmd->cmd_post, sizeof (cmd->cmd_post), "%s", args->post);
+ snprintf(cmd->cmd_log, sizeof (cmd->cmd_log), "%s", args->log);
+
cmd->cmd_id = id;
cmd->cmd_chunk_size = C;
cmd->cmd_thread_count = T;
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);
}