Bug 166349 - Support the assignment-allocation character for fscanf()/scanf()/sscanf()
Summary: Support the assignment-allocation character for fscanf()/scanf()/sscanf()
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-23 19:10 UTC by Nathan Weeks
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments
file.txt (233 bytes, text/plain)
2012-03-23 19:10 UTC, Nathan Weeks
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Weeks 2012-03-23 19:10:13 UTC
In POSIX.1-2008, the %c , %s , and %[ conversion specifiers in a
fscanf()/scanf()/sscanf() format string accept an optional
assignment-allocation character 'm' to allocate a memory buffer large enough
to hold the converted string:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/fscanf.html

This functionality is useful for safely reading formatted input strings of unknown size.

The FreeBSD 9.0 libc does not support this feature.

In addition, the gcc 4.6.3 port silently accepts the assignment-allocation character, even when "-Wall" is specified, but a memory buffer is apparently not allocated at run time.

Fix: Patch attached with submission follows:
How-To-Repeat: Compile the attached program (scanf_m.c) using the base gcc 4.2.1:

#####################################
$ gcc -Wall scanf_m.c
scanf_m.c: In function 'main':
scanf_m.c:6: warning: unknown conversion type character 'm' in format
scanf_m.c:6: warning: too many arguments for format
$ echo test | ./a.out
H??
Segmentation fault (core dumped)
#####################################

Using the gcc 4.6.3 port:
#####################################
$ gcc46 -Wall scanf_m.c
$ echo test | ./a.out
H??
Segmentation fault (core dumped)
#####################################
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:44 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped