Bug 141423 - -D_FORTIFY_SOURCE=2 breaks build of alsa-lib
Summary: -D_FORTIFY_SOURCE=2 breaks build of alsa-lib
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: alsa-lib
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-12-01 01:21 UTC by Bill Nottingham
Modified: 2014-03-17 02:51 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2004-12-01 16:31:59 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Bill Nottingham 2004-12-01 01:21:24 UTC
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-12-01 03:43:18 UTC
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 06:32:49 UTC
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);
and
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 16:31:59 UTC
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.