diff --git a/daemon/utils.c b/daemon/utils.c index a23f3a941..127ee3050 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -638,11 +638,6 @@ mountable_to_string (const mountable_t *mountable) } } -#if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40800 /* gcc >= 4.8.0 */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstack-usage=" -#endif - /** * Check program exists and is executable on C<$PATH>. */ @@ -650,23 +645,20 @@ int prog_exists (const char *prog) { const char *pathc = getenv ("PATH"); - if (!pathc) return 0; - const size_t proglen = strlen (prog); + CLEANUP_FREE char *path = strdup (pathc); + if (path == NULL) abort (); + const char *elem; char *saveptr; - const size_t len = strlen (pathc) + 1; - char path[len]; - strcpy (path, pathc); elem = strtok_r (path, ":", &saveptr); while (elem) { - const size_t n = strlen (elem) + proglen + 2; - char testprog[n]; + CLEANUP_FREE char *testprog; - snprintf (testprog, n, "%s/%s", elem, prog); + if (asprintf (&testprog, "%s/%s", elem, prog) == -1) abort (); if (access (testprog, X_OK) == 0) return 1; @@ -677,10 +669,6 @@ prog_exists (const char *prog) return 0; } -#if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40800 /* gcc >= 4.8.0 */ -#pragma GCC diagnostic pop -#endif - /** * Pass a template such as C<"/sysroot/XXXXXXXX.XXX">. This updates * the template to contain a randomly named file. Any C<'X'>