From: Hans Dedecker Date: Mon, 22 Jan 2018 17:51:23 +0000 (+0100) Subject: trace: check asprintf() return value X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=653629f19e591a0827ab39de07b4526bb119a57a;p=oweals%2Fprocd.git trace: check asprintf() return value Check asprintf() return value; fixes ignoring return value warnings: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Hans Dedecker --- diff --git a/trace/trace.c b/trace/trace.c index 1c1e757..27cf108 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -317,13 +317,17 @@ int main(int argc, char **argv, char **envp) case SECCOMP_TRACE: preload = "/lib/libpreload-seccomp.so"; newenv = 2; - asprintf(&_envp[1], "SECCOMP_FILE=%s", json ? json : ""); + if (asprintf(&_envp[1], "SECCOMP_FILE=%s", json ? json : "") < 0) + ULOG_ERR("failed to allocate SECCOMP_FILE env: %m\n"); + kill(getpid(), SIGSTOP); break; } - asprintf(&_envp[0], "LD_PRELOAD=%s%s%s", preload, - old_preload ? ":" : "", - old_preload ? old_preload : ""); + if (asprintf(&_envp[0], "LD_PRELOAD=%s%s%s", preload, + old_preload ? ":" : "", + old_preload ? old_preload : "") < 0) + ULOG_ERR("failed to allocate LD_PRELOAD env: %m\n"); + memcpy(&_envp[newenv], envp, envc * sizeof(char *)); ret = execve(_argv[0], _argv, _envp); @@ -383,7 +387,8 @@ int main(int argc, char **argv, char **envp) case SECCOMP_TRACE: if (!violation_count) return 0; - asprintf(&json, "/tmp/%s.%u.violations.json", basename(*argv), child); + if (asprintf(&json, "/tmp/%s.%u.violations.json", basename(*argv), child) < 0) + ULOG_ERR("failed to allocate violations output path: %m\n"); break; } print_syscalls(policy, json);