Blame libtracefs-Don-t-leak-socket-file-descriptor-in-open.patch
|
Jerome Marchand |
3772ca |
From a01d0ba2d810336870deb8fd4f5366fee45865fe Mon Sep 17 00:00:00 2001
|
|
Jerome Marchand |
3772ca |
From: Jerome Marchand <jmarchan@redhat.com>
|
|
Jerome Marchand |
3772ca |
Date: Thu, 6 Jun 2024 17:38:20 +0200
|
|
Jerome Marchand |
3772ca |
Subject: [PATCH 06/15] libtracefs: Don't leak socket file descriptor in
|
|
Jerome Marchand |
3772ca |
open_vsock()
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
Close the socket file descriptor if connect() fails.
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
Fixes a RESSOURCE_LEAK error (CWE-772)
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
Link: https://lore.kernel.org/linux-trace-devel/20240606153830.2666120-7-jmarchan@redhat.com
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
Fixes: 5ea41283fa071 ("libtracefs: Add tracefs_find_cid_pid() API")
|
|
Jerome Marchand |
3772ca |
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
|
|
Jerome Marchand |
3772ca |
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
|
|
Jerome Marchand |
3772ca |
---
|
|
Jerome Marchand |
3772ca |
src/tracefs-vsock.c | 4 +++-
|
|
Jerome Marchand |
3772ca |
1 file changed, 3 insertions(+), 1 deletion(-)
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
diff --git a/src/tracefs-vsock.c b/src/tracefs-vsock.c
|
|
Jerome Marchand |
3772ca |
index e171382..9171321 100644
|
|
Jerome Marchand |
3772ca |
--- a/src/tracefs-vsock.c
|
|
Jerome Marchand |
3772ca |
+++ b/src/tracefs-vsock.c
|
|
Jerome Marchand |
3772ca |
@@ -19,8 +19,10 @@ static int open_vsock(unsigned int cid, unsigned int port)
|
|
Jerome Marchand |
3772ca |
if (sd < 0)
|
|
Jerome Marchand |
3772ca |
return -1;
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
- if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)))
|
|
Jerome Marchand |
3772ca |
+ if (connect(sd, (struct sockaddr *)&addr, sizeof(addr))) {
|
|
Jerome Marchand |
3772ca |
+ close(sd);
|
|
Jerome Marchand |
3772ca |
return -1;
|
|
Jerome Marchand |
3772ca |
+ }
|
|
Jerome Marchand |
3772ca |
|
|
Jerome Marchand |
3772ca |
return sd;
|
|
Jerome Marchand |
3772ca |
}
|
|
Jerome Marchand |
3772ca |
--
|
|
Jerome Marchand |
3772ca |
2.45.2
|
|
Jerome Marchand |
3772ca |
|