diff mbox series

[7/7] trace-cmd record: Fix stdin redirection to /dev/null

Message ID 20241205144439.127564-8-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit 5f1eeba9f65c49abba262510670fe23064950f7b
Headers show
Series trace-cmd: Fix misc issues uncoverd by static analysis | expand

Commit Message

Jerome Marchand Dec. 5, 2024, 2:44 p.m. UTC
In daemonize_start(), stdin file descriptor is closed after the call
to dup2. This doesn't make sense and could lead to FD zero being
reused. I assume the original intend was to close the devnull FD which
in the current code remains opened while the devnull variable goes out
of scope.

Close devnull instead of 0.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 tracecmd/trace-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 6e9b4535..fe9ceaa8 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -1677,7 +1677,7 @@  static void daemonize_start(void)
 		if (devnull > 0) {
 			if (dup2(devnull, 0) == -1)
 				die("daemonize: dup2");
-			close(0);
+			close(devnull);
 		}
 
 		return;