comparison src/video/SDL_stretch.c @ 4355:9b464226e541 SDL-1.2

Fixed bug #855 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.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 18 Oct 2009 17:31:37 +0000
parents a1b03ba2fcd0
children ab2dfac9d5c1
comparison
equal deleted inserted replaced
4354:1e191391e68d 4355:9b464226e541
101 break; 101 break;
102 default: 102 default:
103 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); 103 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp);
104 return(-1); 104 return(-1);
105 } 105 }
106 #ifdef HAVE_MPROTECT
107 /* Make the code writeable */
108 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE) < 0 ) {
109 SDL_SetError("Couldn't make copy buffer writeable");
110 return(-1);
111 }
112 #endif
106 pos = 0x10000; 113 pos = 0x10000;
107 inc = (src_w << 16) / dst_w; 114 inc = (src_w << 16) / dst_w;
108 eip = copy_row; 115 eip = copy_row;
109 for ( i=0; i<dst_w; ++i ) { 116 for ( i=0; i<dst_w; ++i ) {
110 while ( pos >= 0x10000L ) { 117 while ( pos >= 0x10000L ) {
126 if ( eip > (copy_row+sizeof(copy_row)) ) { 133 if ( eip > (copy_row+sizeof(copy_row)) ) {
127 SDL_SetError("Copy buffer overflow"); 134 SDL_SetError("Copy buffer overflow");
128 return(-1); 135 return(-1);
129 } 136 }
130 #ifdef HAVE_MPROTECT 137 #ifdef HAVE_MPROTECT
131 /* Make the code executable */ 138 /* Make the code executable but not writeable */
132 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_WRITE|PROT_EXEC) < 0 ) { 139 if ( mprotect(copy_row, sizeof(copy_row), PROT_READ|PROT_EXEC) < 0 ) {
133 SDL_SetError("Couldn't make copy buffer executable"); 140 SDL_SetError("Couldn't make copy buffer executable");
134 return(-1); 141 return(-1);
135 } 142 }
136 #endif 143 #endif
137 last.status = 0; 144 last.status = 0;