I: [PATCH] asprintf error handling fix
Dmitry V. Levin
ldv@alt-linux.org
Mon Dec 10 06:34:00 GMT 2001
On Fri, Dec 07, 2001 at 07:57:39AM -0800, Ulrich Drepper wrote:
> > I'm talking about already written software which rely on zeroing
> > result_ptr.
>
> There is no such software using glibc. Changing this (which is
Unfortunately, there are software using asprintf in BSD-like way.
When ported to glibc, it gets broken if asprintf calls aren't fixed.
> completely unnecessary) will create an incompatibility. Newly
> developed code might check only for the NULL pointer value and these
> programs would then fail with older glibc versions.
It's glibc's maintainer's (debatable) point of view.
There is another point of view. Imagine you are gnu/linux distribution
vendor. You have a lot of software so you have no ability to audit it all
in reasonable short time. You start to audit core of system, and see
non-obvious asprintf usage. You check the glibc code, and understand that
both program and glibc require fix, patch them and notify maintainers
(it's real story how this asprintf bug was found). Fine, both glibc and
broken program fixed, but what to do with rest of software in
distribution? Fix it altogether is unrealistic, since amount is large
(remember even glibc code had almost no check for asprintf return status).
Yes, suggested asprintf API change is kind of hardening, but for
distribution vendor it's a real help to partially fix software.
So don't surprise if distribution vendors will apply this patch
(attached).
Regards,
Dmitry
+-------------------------------------------------------------------------+
Dmitry V. Levin mailto://ldv@alt-linux.org
ALT Linux Team http://www.altlinux.ru/
Fandra Project http://www.fandra.org/
+-------------------------------------------------------------------------+
UNIX is user friendly. It's just very selective about who its friends are.
-------------- next part --------------
2001-12-10 Dmitry V. Levin <ldv@alt-linux.org>
* libio/vasprintf.c (_IO_vasprintf): Zero result_ptr in case of error.
--- glibc-20011210~/libio/vasprintf.c Thu Dec 6 13:14:41 2001
+++ glibc-20011210/libio/vasprintf.c Mon Dec 10 16:17:39 2001
@@ -48,7 +48,10 @@
_IO_size_t allocated;
string = (char *) malloc (init_string_size);
if (string == NULL)
- return -1;
+ {
+ *result_ptr = NULL;
+ return -1;
+ }
#ifdef _IO_MTSAFE_IO
sf._sbf._f._lock = NULL;
#endif
@@ -62,6 +65,7 @@
if (ret < 0)
{
free (sf._sbf._f._IO_buf_base);
+ *result_ptr = NULL;
return ret;
}
/* Only use realloc if the size we need is of the same order of
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20011210/6974e617/attachment.sig>
More information about the Libc-alpha
mailing list