From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
Cc: namhyung@kernel.org, peterz@infradead.org, mingo@redhat.com,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] perf daemon: Fix file leak in daemon_session__control
Date: Fri, 10 May 2024 11:28:58 -0300 [thread overview]
Message-ID: <Zj4vKps94GwVBwQ5@x1> (raw)
In-Reply-To: <20240510003424.2016914-1-samasth.norway.ananda@oracle.com>
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
prev parent reply other threads:[~2024-05-10 14:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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=Zj4vKps94GwVBwQ5@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=samasth.norway.ananda@oracle.com \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).