Bug 141423 - -D_FORTIFY_SOURCE=2 breaks build of alsa-lib
-D_FORTIFY_SOURCE=2 breaks build of alsa-lib
Product: Fedora
Classification: Fedora
Component: alsa-lib (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
Depends On:
  Show dependency treegraph
Reported: 2004-11-30 20:21 EST by Bill Nottingham
Modified: 2014-03-16 22:51 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-12-01 11:31:59 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Bill Nottingham 2004-11-30 20:21:24 EST
x86_64-redhat-linux-gcc -DHAVE_CONFIG_H -I. -I. -I../include
-I../include -O2 -g -pipe -D_FORTIFY_SOURCE=2 -m64 -MT input.lo -MD
-MP -MF .deps/input.Tpo -c input.c  -fPIC -DPIC -o .libs/input.o
input.c:96:42: macro "gets" passed 3 arguments, but takes just 1
input.c: In function `snd_input_gets':
input.c:96: warning: return from incompatible pointer type

Relevant code is:

typedef struct _snd_input_ops {
        int (*close)(snd_input_t *input);
        int (*scan)(snd_input_t *input, const char *format, va_list args);
        char *(*gets)(snd_input_t *input, char *str, size_t size);
        int (*getch)(snd_input_t *input);
        int (*ungetch)(snd_input_t *input, int c);
} snd_input_ops_t;

struct _snd_input {
        snd_input_type_t type;
        snd_input_ops_t *ops;
        void *private_data;
typedef struct _snd_input snd_input_t;

char *snd_input_gets(snd_input_t *input, char *str, size_t size)
        return input->ops->gets(input, str, size);
Comment 1 Bill Nottingham 2004-11-30 22:43:18 EST
Fixed in alsa-lib with a '#undef gets' in input.c

Feel free to close if you don't want to be too liberal in accepting
wacky code. :)
Comment 2 Jakub Jelinek 2004-12-01 01:32:49 EST
alsa-lib is broken:
ISO C 99, 7.1.4:
Any function declared in a header may be additionally implemented as a
function-like macro defined in the header, so if a library function is
declared explicitly when its header is included, one of the techniques
shown below can be used to ensure the declaration is not affected by such a
macro.  Any macro definition of a function can be suppressed locally by
enclosing the name of the function in parentheses, because the name is
then not followed by the left parenthesis that indicates expansion of
a macro function name.  For the same syntactic reason, it is permitted
to take the address of a library function even if it is also defined
as a macro.  The use of #undef to remove any macro definition will also
ensure that an actual function is referred to.

In this case, I think it would be better to 
char *(*(gets))(snd_input_t *input, char *str, size_t size);
return (input->ops->gets)(input, str, size);
because that way instead of the #undef way if alsa-lib ever uses gets (str)
function, it will turn a buffer overflow into just a DoS.
Comment 3 Bill Nottingham 2004-12-01 11:31:59 EST
Fixed in CVS, will be in -7 or later.

Note You need to log in before you can comment on or make changes to this bug.