I: [PATCH] asprintf error handling fix
Dmitry V. Levin
ldv@alt-linux.org
Wed Dec 5 10:59:00 GMT 2001
Greetings!
Current asprintf (to be more exact, _IO_vasprintf) implementation
appears to have two defects:
- When _IO_vfprintf call fails, _IO_vasprintf returns error code without
freeing memory allocated before (either in this function or during
_IO_vfprintf execution).
- When either malloc or _IO_vfprintf call fails, _IO_vasprintf returns
error code without setting result_ptr to zero.
First defect seems to have obvious fix.
You may ask why asprintf should zero result_ptr in case of error?
There are several reasons:
+ It's reasonable and expected behaviour.
+ The asprintf function is widely used by glibc itself, and almost
everywhere it assumes result_ptr gets null value in case of error; I've tried to
catch all such cases, but anyway better to avoid potential problems.
+ All BSD libc implementations do that, so porting asprintf based software
from *BSD to glibc becomes a nightmare if asprintf API differs.
2001-12-05 Dmitry V. Levin <ldv@alt-linux.org>
* libio/vasprintf.c (_IO_vasprintf): Fix error handling.
* assert/assert-perr.c: Check asprintf return code.
* assert/assert.c: Likewise.
* inet/rcmd.c: Likewise.
* locale/programs/localedef.c: Likewise.
* posix/getopt.c: Likewise.
* resolv/res_hconf.c: Likewise.
* stdio-common/psignal.c: Likewise.
* sunrpc/svc_simple.c: Likewise.
* manual/stdio.texi: Reflect change in asprintf API.
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 --------------
A non-text attachment was scrubbed...
Name: glibc-20011205-asprintf-error_handling.patch.gz
Type: application/x-gzip
Size: 4090 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20011205/0422dc77/attachment.bin>
-------------- 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/20011205/0422dc77/attachment.sig>
More information about the Libc-alpha
mailing list