From: Stefano Brivio <sbrivio@redhat.com>
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 [thread overview]
Message-ID: <20220405170514.2963773-17-sbrivio@redhat.com> (raw)
In-Reply-To: <20220405170514.2963773-1-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]
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 <sbrivio(a)redhat.com>
---
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");
}
}
--
@@ -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
prev parent reply other threads:[~2022-04-05 17:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 17:04 [PATCH 00/16] Fix issues reported by Coverity Stefano Brivio
2022-04-05 17:04 ` [PATCH 01/16] treewide: Invalid type in argument to printf format specifier, CWE-686 Stefano Brivio
2022-04-05 17:05 ` [PATCH 02/16] passt: Ignoring number of bytes read, CWE-252 Stefano Brivio
2022-04-05 17:05 ` [PATCH 03/16] tcp: False "Untrusted loop bound" positive, CWE-606 Stefano Brivio
2022-04-05 17:05 ` [PATCH 04/16] treewide: Unchecked return value from library, CWE-252 Stefano Brivio
2022-04-05 17:05 ` [PATCH 05/16] tap: Resource leak, CWE-404 Stefano Brivio
2022-04-05 17:05 ` [PATCH 06/16] conf, packet: Operands don't affect result, CWE-569 Stefano Brivio
2022-04-05 17:05 ` [PATCH 07/16] passt: Improper use of negative value (CWE-394) Stefano Brivio
2022-04-05 17:05 ` [PATCH 08/16] treewide: Argument cannot be negative, CWE-687 Stefano Brivio
2022-04-05 17:05 ` [PATCH 09/16] conf: False "Assign instead of compare" positive, CWE-481 Stefano Brivio
2022-04-05 17:05 ` [PATCH 10/16] conf, tap: False "Buffer not null terminated" positives, CWE-170 Stefano Brivio
2022-04-05 17:05 ` [PATCH 11/16] tcp: Dereference null return value, CWE-476 Stefano Brivio
2022-04-05 17:05 ` [PATCH 12/16] tcp_splice: Logically dead code, CWE-561 Stefano Brivio
2022-04-05 17:05 ` [PATCH 13/16] tcp, tcp_splice: False "Negative array index read" positives, CWE-129 Stefano Brivio
2022-04-05 17:05 ` [PATCH 14/16] tcp: False "Out-of-bounds read" positive, CWE-125 Stefano Brivio
2022-04-05 17:05 ` [PATCH 15/16] udp: Out-of-bounds read, CWE-125 in udp_timer() Stefano Brivio
2022-04-05 17:05 ` Stefano Brivio [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220405170514.2963773-17-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).