[PATCH v4] libio: asprintf should write NULL upon failure

Solar Designer solar@openwall.com
Fri Sep 13 15:59:46 GMT 2024


Hi Florian,

On Tue, Aug 13, 2024 at 08:27:26PM +0200, Solar Designer wrote:
> On Mon, Aug 12, 2024 at 11:57:25AM +0200, Florian Weimer wrote:
> > +++ b/manual/stdio.texi
> > @@ -2517,7 +2517,14 @@ Allocation}) to hold the output, instead of putting the output in a
> >  buffer you allocate in advance.  The @var{ptr} argument should be the
> >  address of a @code{char *} object, and a successful call to
> >  @code{asprintf} stores a pointer to the newly allocated string at that
> > -location.
> > +location.  Current and future versions of @theglibc{} write a null
> > +pointer to @samp{*@var{ptr}} upon failure.  To achieve similar
> > +behavior with previous versions, initialize @samp{*@var{ptr}} to a
> > +null pointer before calling @code{asprintf}.  (Specifications for
> > +@code{asprintf} only require a valid pointer value in
> > +@samp{*@var{ptr}} if @code{asprintf} succeeds, but no implementations
> > +are known which overwrite a null pointer with a pointer that cannot be
> > +freed on failure.)
> 
> Thanks.  I'm not happy that this doesn't suggest the only guaranteed
> correct usage per POSIX (check the return value), but like I wrote
> before I didn't mean to delay getting these changes in by commenting on
> the documentation.  So let's proceed with the above.

What's the status on this?  I really did not mean to delay getting this
in.  If my comments have caused delay, then please disregard them.

Thanks,

Alexander


More information about the Libc-alpha mailing list