1

The paxtest program includes some interesting tests, among many others it apparently tests if strcpy and memcpy can overwrite a return pointer on the stack:

(from rettofunc1.c)

void doit( void )
{ 
    char buf[4];

    if (strlen((const char *)overflow) > sizeof(overflow[0])) {
        strcpy( buf, (const char *)overflow );
    } else {
        fprintf( stderr, "paxtest: return address contains a NULL byte.\n" );
        exit(1);
    }
}

and (from rettofunc2.c)

void doit( void )
{     
     char buf[4];

    memcpy( buf, overflow, sizeof( overflow ) );
}

My question is why is my system (standard Slackware 14.0, unpatched) vulnerable to strcpy but not memcpy? Why does it matter which function is used to write to the stack?

It should also be noted that this was compiled for 32-bit, with 64-bit the return address contains a NULL byte and it fails with strcpy too.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
csstudent2233
  • 659
  • 10
  • 17

0 Answers0