Launchpad has imported 3 comments from the remote bug at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35948.

If you reply to an imported comment from within Launchpad, your comment
will be sent to the remote bug automatically. Read more about
Launchpad's inter-bugtracker facilities at
https://documentation.ubuntu.com/launchpad/user/reference/bugs/multi-project-bugs/about-multi-project-bugs/#bugs-in-external-trackers.

------------------------------------------------------------------------
On 2008-04-15T16:28:40+00:00 Kees Cook wrote:

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;
}

Reply at:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/217481/comments/1

------------------------------------------------------------------------
On 2008-04-15T16:35:26+00:00 Pinskia wrote:

This is not a GCC bug but rather a glibc issue.


Reply at: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/217481/comments/2

------------------------------------------------------------------------
On 2008-04-15T16:44:12+00:00 Kees Cook wrote:

Erk, right.  Sorry for the noise.

Reply at:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/217481/comments/3

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/217481

Title:
  -D_FORTIFY_SOURCE discards qualifier overrides in {mem,str}cpy

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/217481/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to