Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Steven Rostedt <rostedt@goodmis.org>, linux-trace-devel@vger.kernel.org
Cc: cocci@inria.fr
Subject: Re: [cocci] [PATCH v3] trace-cmd: Check all strdup() return values
Date: Sat, 3 Jun 2023 13:20:37 +0200	[thread overview]
Message-ID: <8b23bb42-0b20-850f-b155-c407b671fdda@web.de> (raw)
In-Reply-To: <20230603054450.1e83841a@rorschach.local.home>

…
> to find all the locations that did not check the return value of strdup().
> As the coccinelle script adds a FIXME to the text. Then I went through and
> updated each location to handle the action appropriately.
>
> Signed-off-by:
…

Will it be relevant to refer to any previous bug report for the discussed
source code transformation?

Example:
Completion of error handling
https://bugzilla.kernel.org/show_bug.cgi?id=217126> +++ b/lib/trace-cmd/trace-msg.c
> @@ -1229,6 +1229,8 @@ static int get_trace_req_protos(char *buf, int length,
>  	while (i > 0 && j < (count - 1)) {
>  		i -= strlen(p) + 1;
>  		plist->names[j++] = strdup(p);
> +		if (plist->names[j++] == NULL)
> +			goto error;
>  		p += strlen(p) + 1;
>  	}

I suggest to reconsider the usage of the increment operator in such a statement combination.

Should the pointer from this strdup() call be assigned to another variable
before a corresponding null pointer check is performed?


…
> +++ b/lib/trace-cmd/trace-output.c
> @@ -230,6 +230,7 @@ void tracecmd_set_out_clock(struct tracecmd_output *handle, const char *clock)
>  	if (handle && clock) {
>  		free(handle->trace_clock);
>  		handle->trace_clock = strdup(clock);
> +		/* TODO: report error if failed to allocate */
>  	}
>  }

How will this place be improved?


…
> +++ b/tracecmd/trace-split.c
> @@ -367,6 +367,8 @@ static double parse_file(struct tracecmd_input *handle,
>  	int fd;
>
>  	output = strdup(output_file);
> +	if (output == NULL)
> +		die("Failed to allocate output_file");
>  	dir = dirname(output);
>  	base = basename(output);

Would an error message like “String duplication failed for output_file” be nicer?

Regards,
Markus

           reply	other threads:[~2023-06-03 11:20 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20230603054450.1e83841a@rorschach.local.home>]

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=8b23bb42-0b20-850f-b155-c407b671fdda@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@inria.fr \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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).