public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: jit@gcc.gnu.org, "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH, jit]: Robustify vasprintf error checks
Date: Thu, 01 Jan 2015 00:00:00 -0000	[thread overview]
Message-ID: <1426269343.8624.206.camel@surprise> (raw)
In-Reply-To: <CAFULd4aGQqy9-g6AC-ZrNs3MaSKTB3q58BdbNbqaESSTo5ZtKA@mail.gmail.com>

On Fri, 2015-03-13 at 17:53 +0100, Uros Bizjak wrote:
> Hello!
> 
> As documented in [1] asprintf and vasprintf return:
> 
> --quote--
> Return value:
> 
> Both functions set *ret to be a pointer to a malloc()'d buffer
> sufficiently large to hold the formatted string. This pointer should
> be passed to free() to release the allocated storage when it is no
> longer needed.
> 
> The integer value returned by these functions is the number of
> characters that were output to the newly allocated string (excluding
> the final '\0'). To put it differently, the return value will match
> that of strlen(*ret).
> 
> Upon failure, the returned value will be -1, and *ret will be set to NULL.
> 
> Note: Upon failure, other implementations may forget to set *ret and
> leave it in an undefined state. Some other implementations may always
> set *ret upon failure but forget to assign -1 for the return value in
> some edge cases.
> --/quote--
> 
> Based on the note above, the attached patch robustifies vasprintf
> return value checks in jit/jit-recording.c. Actually, the same checks
> are already implemented in function oprint, around line 1655 in
> gengtype.c.

> 2015-02-25  Uros Bizjak  <ubizjak@gmail.com>
> 
>     * jit-recording.c (dump::write): Also check vasprintf return value.
>     (recording::context::add_error_va): Ditto.
>     (recording::string::from_printf): Ditto.
> 
> The patch was bootstrapped and regression tested on x86_64-linux-gnu.
> 
> OK for mainline?

Thanks.

I assume that we can rely that any vasprintf implementation manages on
failure to at least either write NULL to *ret or to return -1, even if
some of them fail to do both?

OK for trunk.

> 
> [1] http://asprintf.insanecoding.org/
> 
> Uros.


  reply	other threads:[~2015-03-13 18:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-01  0:00 Uros Bizjak
2015-01-01  0:00 ` David Malcolm [this message]
2015-01-01  0:00   ` Uros Bizjak

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=1426269343.8624.206.camel@surprise \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jit@gcc.gnu.org \
    --cc=ubizjak@gmail.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).