linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control
@ 2024-05-10  0:34 Samasth Norway Ananda
  2024-05-10 14:28 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Samasth Norway Ananda @ 2024-05-10  0:34 UTC (permalink / raw)
  To: namhyung, acme
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, irogers,
	adrian.hunter, linux-perf-users, linux-kernel,
	samasth.norway.ananda

The open() function returns -1 on error.
'control' and 'ack' both initialized with open() and further
validated with 'if' statement. 'if (!control)' would evaluate
to 'true' if returned value on error were '0' but it is actually '-1'.

Fixes: edcaa47958c7 ("perf daemon: Add 'ping' command")
Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
---
Found this error through static analysis. This has only been compile
tested.
---
 tools/perf/builtin-daemon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index 83954af36753..de76bbc50bfb 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -523,7 +523,7 @@ static int daemon_session__control(struct daemon_session *session,
 		  session->base, SESSION_CONTROL);
 
 	control = open(control_path, O_WRONLY|O_NONBLOCK);
-	if (!control)
+	if (control < 0)
 		return -1;
 
 	if (do_ack) {
@@ -532,7 +532,7 @@ static int daemon_session__control(struct daemon_session *session,
 			  session->base, SESSION_ACK);
 
 		ack = open(ack_path, O_RDONLY, O_NONBLOCK);
-		if (!ack) {
+		if (ack < 0) {
 			close(control);
 			return -1;
 		}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control
  2024-05-10  0:34 [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control Samasth Norway Ananda
@ 2024-05-10 14:28 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-05-10 14:28 UTC (permalink / raw)
  To: Samasth Norway Ananda
  Cc: namhyung, peterz, mingo, mark.rutland, alexander.shishkin, jolsa,
	irogers, adrian.hunter, linux-perf-users, linux-kernel

On Thu, May 09, 2024 at 05:34:24PM -0700, Samasth Norway Ananda wrote:
> The open() function returns -1 on error.
> 'control' and 'ack' both initialized with open() and further
> validated with 'if' statement. 'if (!control)' would evaluate
> to 'true' if returned value on error were '0' but it is actually '-1'.
> 
> Fixes: edcaa47958c7 ("perf daemon: Add 'ping' command")
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>

Thanks, applied to perf-tools-next,

- Arnaldo

> ---
> Found this error through static analysis. This has only been compile
> tested.
> ---
>  tools/perf/builtin-daemon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
> index 83954af36753..de76bbc50bfb 100644
> --- a/tools/perf/builtin-daemon.c
> +++ b/tools/perf/builtin-daemon.c
> @@ -523,7 +523,7 @@ static int daemon_session__control(struct daemon_session *session,
>  		  session->base, SESSION_CONTROL);
>  
>  	control = open(control_path, O_WRONLY|O_NONBLOCK);
> -	if (!control)
> +	if (control < 0)
>  		return -1;
>  
>  	if (do_ack) {
> @@ -532,7 +532,7 @@ static int daemon_session__control(struct daemon_session *session,
>  			  session->base, SESSION_ACK);
>  
>  		ack = open(ack_path, O_RDONLY, O_NONBLOCK);
> -		if (!ack) {
> +		if (ack < 0) {
>  			close(control);
>  			return -1;
>  		}
> -- 
> 2.42.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-10 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-10  0:34 [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control Samasth Norway Ananda
2024-05-10 14:28 ` Arnaldo Carvalho de Melo

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 NNTP newsgroup(s).