All of lore.kernel.org
 help / color / mirror / Atom feed
* Issue with asprintf()
@ 2015-05-11 22:46 Archie Cobbs
       [not found] ` <CANSoFxs8XW6Z7ph2Uy1wFdeQPOGb7zvwJKExSLoUrMQ94b-8XA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Archie Cobbs @ 2015-05-11 22:46 UTC (permalink / raw)
  To: mtk-manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

Hi,

There seems to be an issue with the asprintf() man page and underlying
implementation (I'm using openSUSE 13.1 - man-pages-3.53).

Since asprintf() is not POSIX, the man page effectively becomes the
specification of its behavior. The man page says:

    If memory allocation wasn't possible, or some other error occurs,
these functions will return -1, and the contents of strp is undefined.

The problem is that:

  o What actually happens is that the contents of strp are
_unmodified_ (not _undefined_)
  o There is critical code out there that depends on this undocumented
behavior (e.g., systemd)
  o Maintainers of that critical code don't believe their code doing
anything wrong (https://bugs.freedesktop.org/show_bug.cgi?id=90017)

This is a great way to create a security hole five years from now,
when someone optimizes asprintf() so that it actually does clobber
strp on error.

One argument says well, Leonnard is just wrong .. but let's not
restart that debate here :)

On the other hand, he has a good point: a much simpler fix, which
would make life easier for programmers everywhere, would be to change
the specified behavior from undefined -> unmodified, because this
allows the caller to initialize strp to NULL and get back a
free()'able value no matter what.

So... is is possible to tighten the "undefined" to be "unmodified" and
reflect reality?

FWIW, FreeBSD sets *strp to null on error, which is even nicer for the
programmer.

-Archie

-- 
Archie L. Cobbs
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-05-12 13:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11 22:46 Issue with asprintf() Archie Cobbs
     [not found] ` <CANSoFxs8XW6Z7ph2Uy1wFdeQPOGb7zvwJKExSLoUrMQ94b-8XA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-12  2:58   ` Mike Frysinger
2015-05-12  5:17     ` Michael Kerrisk (man-pages)
     [not found]       ` <CAKgNAkjemzRg4OM02rQa2OLPU_EKJEDRcHWGpEFnNFvpkA02vQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-12 13:35         ` Archie Cobbs

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.