rodata section is writable.......

rodata section is writable.......

Hi,

I wrote a simple test file and compiled it using icc compiler. In the program I tried to overwrite the data which is in the section rodata. Compiler thrown a warning but it's allowing me to overwrite it. Here is the way I did....

test.c

#include<stdio.h>

int main()
{
        const char arr[20]="abcdefgh";
        char ch[10]="zzzzzzZ";

        memcpy(arr,ch,10);

        printf("after writing to arr:%s\n",arr);

        return 0;

}

#icc.12.0.022b.i686-linux test_crash.c
#test_crash.c(22): warning #2330: argument of type "const char *" is incompatible with parameter of type "void *" (dropping qualifiers)
        memcpy(arr,ch,10);
               ^

Output:

# ./a.out
after writing to arr:zzzzzzZ

 

But My intention is to provide some protection for the rodata section....

How can I achieve this???

Any compiler options available to do this??

 

Thanks,

Vijaya.

 

 

 

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.