git: 5143ea18e510 - stable/14 - pmcannotate: avoid accessing uninitialized local variables
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 29 Dec 2025 02:12:30 UTC
The branch stable/14 has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=5143ea18e51042811bfb8be2b14e57befbde10fe
commit 5143ea18e51042811bfb8be2b14e57befbde10fe
Author: Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-12-26 13:37:47 +0000
Commit: Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-12-29 02:11:35 +0000
pmcannotate: avoid accessing uninitialized local variables
Initialize `tbfl` and `tofl` to NULL, and check whether they are
non-NULL before calling remove(3) on them, to avoid warnings from clang
21 similar to:
usr.sbin/pmcannotate/pmcannotate.c:746:3: error: variable 'tbfl' is uninitialized when used here [-Werror,-Wuninitialized]
746 | FATAL(exec, "%s: Impossible to locate the binary file\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
747 | exec);
| ~~~~~
usr.sbin/pmcannotate/pmcannotate.c:57:9: note: expanded from macro 'FATAL'
57 | remove(tbfl); \
| ^~~~
usr.sbin/pmcannotate/pmcannotate.c:695:12: note: initialize the variable 'tbfl' to silence this warning
695 | char *tbfl, *tofl, *tmpdir;
| ^
| = NULL
usr.sbin/pmcannotate/pmcannotate.c:746:3: error: variable 'tofl' is uninitialized when used here [-Werror,-Wuninitialized]
746 | FATAL(exec, "%s: Impossible to locate the binary file\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
747 | exec);
| ~~~~~
usr.sbin/pmcannotate/pmcannotate.c:58:9: note: expanded from macro 'FATAL'
58 | remove(tofl); \
| ^~~~
usr.sbin/pmcannotate/pmcannotate.c:695:19: note: initialize the variable 'tofl' to silence this warning
695 | char *tbfl, *tofl, *tmpdir;
| ^
| = NULL
MFC after: 3 days
(cherry picked from commit cd880010c49a5d4ec529f4204d4e88cd27727255)
---
usr.sbin/pmcannotate/pmcannotate.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/usr.sbin/pmcannotate/pmcannotate.c b/usr.sbin/pmcannotate/pmcannotate.c
index c00e4b2a33bc..9c11018135c3 100644
--- a/usr.sbin/pmcannotate/pmcannotate.c
+++ b/usr.sbin/pmcannotate/pmcannotate.c
@@ -55,8 +55,10 @@
if ((ptr) != NULL) \
perror(ptr); \
fprintf(stderr, ##x); \
- remove(tbfl); \
- remove(tofl); \
+ if (tbfl != NULL) \
+ remove(tbfl); \
+ if (tofl != NULL) \
+ remove(tofl); \
exit(EXIT_FAILURE); \
} while (0)
@@ -703,6 +705,8 @@ main(int argc, char *argv[])
uintptr_t tmppc, ostart, oend;
int cget, asmsrc;
+ tbfl = NULL;
+ tofl = NULL;
exec = argv[0];
ofile = NULL;
bin = NULL;