Skip to content

Commit

Permalink
Fixed bug #855
Browse files Browse the repository at this point in the history
 Ludwig Nussel      2009-10-18 06:31:52 PDT

an mprotect call was added to fix bug 528. However that results in a buffer
that allows writing and code execution. Ie the no-execute security features of
modern operating systems are defeated this way. Two mprotect calls are needed.
One to make the buffer executable but not writeable when done and another one
to make the buffer writeable again if the content needs to be changed.
  • Loading branch information
slouken committed Oct 18, 2009
1 parent a418ee0 commit 55d8418
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/video/SDL_stretch.c
Expand Up @@ -103,6 +103,13 @@ static int generate_rowbytes(int src_w, int dst_w, int bpp)
SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp);
return(-1);
}
#ifdef HAVE_MPROTECT
/* Make the code writeable */
if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE) < 0 ) {
SDL_SetError("Couldn't make copy buffer writeable");
return(-1);
}
#endif
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
Expand All @@ -128,8 +135,8 @@ static int generate_rowbytes(int src_w, int dst_w, int bpp)
return(-1);
}
#ifdef HAVE_MPROTECT
/* Make the code executable */
if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE|PROT_EXEC) < 0 ) {
/* Make the code executable but not writeable */
if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) {
SDL_SetError("Couldn't make copy buffer executable");
return(-1);
}
Expand Down

0 comments on commit 55d8418

Please sign in to comment.