Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001496 [1003.1(2013)/Issue7+TC1] System Interfaces Comment Enhancement Request 2021-08-01 17:09 2021-08-03 19:19
Reporter alanc View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Alan Coopersmith
Organization Oracle Solaris Engineering
User Reference
Section printf()
Page Number (page or range of pages)
Line Number (Line or range of lines)
Interp Status ---
Final Accepted Text
Summary 0001496: Add asprintf() and vasprintf()
Description The GNU C library has provided asprintf() and vasprintf() since at least 1991,
and many other OS'es have added them as well since. These variants of sprintf()
allocate new memory for the string, making it easier to have a safe usage
without having to re-implement much of the printf format string handling logic
to determine how much memory to allocate. These have been widely adopted in
software trying to avoid buffer overflows: codesearch.debian.net finds 1713
software packages referencing asprintf().

GNU C library documentation:
https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html [^]

FreeBSD man page (added in 2.2 in 1997):
https://www.freebsd.org/cgi/man.cgi?query=asprintf [^]

OpenBSD man page (added in 2.3 in 1998):
https://man.openbsd.org/asprintf.3 [^]

NetBSD man page:
https://man.netbsd.org/asprintf.3 [^]

Solaris man page (added in Solaris 10 Update 10 in 2011):
https://docs.oracle.com/cd/E88353_01/html/E37843/asprintf-3c.html [^]

illumos man page:
https://illumos.org/man/3c/asprintf [^]
Desired Action These functions should be added to the standard:

#include <stdio.h>

int asprintf(char **restrict strp, const char *restrict fmt, ...);
int vasprintf(char **restrict strp, const char *restrict fmt,
              va_list ap);
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0005427)
jsm28 (reporter)
2021-08-02 16:31

Note that these functions (and corresponding aswprintf, vaswprintf) are in ISO/IEC TR 24731-2:2010, so care should be taken to be compatible with the versions there and to raise any issues with the interfaces through the liaison with WG14.

Note also the known error handling issue (it's unspecified whether *ptr is set to NULL on error or left unchanged - apparently this is deliberate in TR 24731-2 to be compatible with multiple existing implementations that make different choices there).
(0005428)
alanc (reporter)
2021-08-03 19:19

Thanks, I was unaware that asprintf() had been specified in that ISO TR.

Of the above listed implementations, all but GNU libc document that they will
set *ptr to NULL on error, while GNU libc explicitly states that you cannot
rely on it to do so (and looking at its code, sometimes it does, sometimes
it doesn't).

- Issue History
Date Modified Username Field Change
2021-08-01 17:09 alanc New Issue
2021-08-01 17:09 alanc Name => Alan Coopersmith
2021-08-01 17:09 alanc Organization => Oracle Solaris Engineering
2021-08-01 17:09 alanc Section => printf()
2021-08-01 17:09 alanc Page Number => (page or range of pages)
2021-08-01 17:09 alanc Line Number => (Line or range of lines)
2021-08-02 16:31 jsm28 Note Added: 0005427
2021-08-03 19:19 alanc Note Added: 0005428


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker