This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/6409] New: (glibc 2.7) -D_FORTIFY_SOURCE discards qualifier overrides on {str,mem}cpy


The following source, without the "(void*)" overrides, will throw an warning
(as expected), when compiled with -Wall:

 $ gcc -o memcpy-fortify -Wall memcpy-fortify.c
 memcpy-fortify.c: In function 'main':
 memcpy-fortify.c:21: warning: passing argument 1 of 'memcpy' discards
qualifiers from pointer target type
 memcpy-fortify.c:22: warning: passing argument 1 of 'strcpy' discards
qualifiers from pointer target type

With "(void*)" it is (as expected) silent. With -O2, it is silent, but with
-D_FORTIFY_SOURCE != 0, the qualifier override is ignored:

 $ gcc -o memcpy-fortify -Wall -O2 -D_FORTIFY_SOURCE=2 memcpy-fortify.c
 memcpy-fortify.c: In function 'main':
 memcpy-fortify.c:21: warning: passing argument 1 of 'memcpy' discards
qualifiers from pointer target type
 memcpy-fortify.c:22: warning: passing argument 1 of 'strcpy' discards
qualifiers from pointer target type

This will cause problems for builds that run with -Werror.

/*
 * gcc -o memcpy-fortify -Wall -Werror -O2 -D_FORTIFY_SOURCE=2 memcpy-fortify.c
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>

int main(int argc, char * argv[])
{
    char *foo = strdup("string one");
    char *bar = strdup("string two");
    const char *baz = (const char *)foo;

    printf("%s\n", foo);

    memcpy((void*)baz, bar, strlen(bar)+1);
    strcpy((void*)baz, bar);

    printf("%s\n", foo);

    return 0;
}

-- 
           Summary: (glibc 2.7) -D_FORTIFY_SOURCE discards qualifier
                    overrides on {str,mem}cpy
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: kees at outflux dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=6409

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]