From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 16/16] arch: Pointer to local outside scope, CWE-562 Date: Tue, 05 Apr 2022 19:05:14 +0200 Message-ID: <20220405170514.2963773-17-sbrivio@redhat.com> In-Reply-To: <20220405170514.2963773-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7833770290234718234==" --===============7833770290234718234== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Reported by Coverity: if we fail to run the AVX2 version, once execve() fails, we had already replaced argv[0] with the new stack-allocated path string, and that's then passed back to main(). Use a static variable instead. Signed-off-by: Stefano Brivio --- arch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch.c b/arch.c index b8e1db5..ae21d59 100644 --- a/arch.c +++ b/arch.c @@ -22,6 +22,8 @@ * @argv: Arguments from command line */ #ifdef __x86_64__ +static char avx2_path[PATH_MAX]; + void arch_avx2_exec(char **argv) { char *p = strstr(argv[0], ".avx2"); @@ -29,11 +31,9 @@ void arch_avx2_exec(char **argv) if (p) { *p = 0; } else if (__builtin_cpu_supports("avx2")) { - char path[PATH_MAX]; - - snprintf(path, PATH_MAX, "%s.avx2", argv[0]); - argv[0] = path; - execve(path, argv, environ); + snprintf(avx2_path, PATH_MAX, "%s.avx2", argv[0]); + argv[0] = avx2_path; + execve(avx2_path, argv, environ); perror("Can't run AVX2 build, using non-AVX2 version"); } } -- 2.35.1 --===============7833770290234718234==--