diff options
Diffstat (limited to 'src/serve.c')
-rw-r--r-- | src/serve.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/serve.c b/src/serve.c index 8fe4966..7dd4647 100644 --- a/src/serve.c +++ b/src/serve.c @@ -395,16 +395,13 @@ static int dcc_check_compiler_whitelist(char *_compiler_name) #ifdef HAVE_FSTATAT int dirfd = open(LIBDIR "/distcc", O_RDONLY); - if (dirfd < 0) { - if (errno == ENOENT) - rs_log_crit("no %s", LIBDIR "/distcc"); - return EXIT_DISTCC_FAILED; - } - if (faccessat(dirfd, compiler_name, X_OK, 0) < 0) { + if (dirfd < 0 || faccessat(dirfd, compiler_name, X_OK, 0) < 0) { char *compiler_path = NULL; - if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { + free(compiler_path); + close(dirfd); rs_log_crit("%s not in %s or %s whitelist.", compiler_name, LIBDIR "/distcc", "/usr/lib/distcc"); return EXIT_BAD_ARGUMENTS; /* ENOENT, EACCESS, etc */ } @@ -412,31 +409,33 @@ static int dcc_check_compiler_whitelist(char *_compiler_name) } } + close(dirfd); + rs_trace("%s in" LIBDIR "/distcc whitelist", compiler_name); return 0; #else // make do with access(): - char *compiler_path = NULL; + char *compiler_path; int ret = 0; - if (asprintf(&compiler_path, "%s/distcc/%s", LIBDIR, compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "%s/distcc/%s", LIBDIR, compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { free(compiler_path); /* check /usr/lib/distcc too */ - if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) && compiler_path) { + if (asprintf(&compiler_path, "/usr/lib/distcc/%s", compiler_name) >= 0) { if (access(compiler_path, X_OK) < 0) { rs_log_crit("%s not in %s or %s whitelist.", compiler_name, LIBDIR "/distcc", "/usr/lib/distcc"); ret = EXIT_BAD_ARGUMENTS; /* ENOENT, EACCESS, etc */ } + free(compiler_path); } - } + } else { + free(compiler_path); + } rs_trace("%s in" LIBDIR "/distcc whitelist", compiler_name); } else { rs_log_crit("Couldn't check if %s is in %s whitelist.", compiler_name, LIBDIR "/distcc"); ret = EXIT_DISTCC_FAILED; } - if (compiler_path) { - free(compiler_path); - } return ret; #endif } @@ -533,7 +532,7 @@ static int tweak_include_arguments_for_server(char **argv, * it augments, rather than replace, the list of targets in the dotd file. * The behavior we want though, is the replacing behavior. * So here we delete the "-MT target" arguments, and we return the target, - * for use in the .d rewritting in dotd.c. + * for use in the .d rewriting in dotd.c. */ static int dcc_convert_mt_to_dotd_target(char **argv, char **dotd_target) { @@ -591,7 +590,9 @@ static int tweak_arguments_for_server(char **argv, if ((ret = dcc_convert_mt_to_dotd_target(*tweaked_argv, dotd_target))) return 1; - dcc_argv_append(*tweaked_argv, strdup("-MMD")); + if (!dcc_argv_search(*tweaked_argv, "-MD") && !dcc_argv_search(*tweaked_argv, "-MMD")) { + dcc_argv_append(*tweaked_argv, strdup("-MMD")); + } dcc_argv_append(*tweaked_argv, strdup("-MF")); dcc_argv_append(*tweaked_argv, strdup(deps_fname)); |