From c1a64be6d40a7eec312902ab72065fe82b945963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sun, 16 May 2021 14:26:42 +0200 Subject: [PATCH] zgenhostid: use argument path directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: John Kennedy Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12042 --- cmd/zgenhostid/zgenhostid.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/cmd/zgenhostid/zgenhostid.c b/cmd/zgenhostid/zgenhostid.c index 5a9bdad7c3..4a4ca80e00 100644 --- a/cmd/zgenhostid/zgenhostid.c +++ b/cmd/zgenhostid/zgenhostid.c @@ -36,8 +36,6 @@ #include #include -static void usage(void); - static void usage(void) { @@ -60,12 +58,11 @@ int main(int argc, char **argv) { /* default file path, can be optionally set by user */ - char path[PATH_MAX] = "/etc/hostid"; + const char *path = "/etc/hostid"; /* holds converted user input or lrand48() generated value */ unsigned long input_i = 0; int opt; - int pathlen; int force_fwrite = 0; while ((opt = getopt_long(argc, argv, "fo:h?", 0, 0)) != -1) { switch (opt) { @@ -73,14 +70,7 @@ main(int argc, char **argv) force_fwrite = 1; break; case 'o': - pathlen = snprintf(path, sizeof (path), "%s", optarg); - if (pathlen >= sizeof (path)) { - fprintf(stderr, "%s\n", strerror(EOVERFLOW)); - exit(EXIT_FAILURE); - } else if (pathlen < 1) { - fprintf(stderr, "%s\n", strerror(EINVAL)); - exit(EXIT_FAILURE); - } + path = optarg; break; case 'h': case '?': @@ -118,7 +108,7 @@ main(int argc, char **argv) if (force_fwrite == 0 && stat(path, &fstat) == 0 && S_ISREG(fstat.st_mode)) { fprintf(stderr, "%s: %s\n", path, strerror(EEXIST)); - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } /*