Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Better fix for bug 936
Browse files Browse the repository at this point in the history
Check to for overruns before they happen instead of afterwards.
  • Loading branch information
slouken committed Jul 18, 2010
1 parent b47d782 commit db6cbc7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/video/SDL_stretch.c
Expand Up @@ -80,7 +80,7 @@ generate_rowbytes(int src_w, int dst_w, int bpp)

int i;
int pos, inc;
unsigned char *eip;
unsigned char *eip, *fence;
unsigned char load, store;

/* See if we need to regenerate the copy buffer */
Expand Down Expand Up @@ -116,14 +116,21 @@ generate_rowbytes(int src_w, int dst_w, int bpp)
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
fence = copy_row + sizeof(copy_row)-2;
for (i = 0; i < dst_w; ++i) {
while (pos >= 0x10000L) {
if (eip == fence) {
return -1;
}
if (bpp == 2) {
*eip++ = PREFIX16;
}
*eip++ = load;
pos -= 0x10000L;
}
if (eip == fence) {
return -1;
}
if (bpp == 2) {
*eip++ = PREFIX16;
}
Expand All @@ -132,11 +139,6 @@ generate_rowbytes(int src_w, int dst_w, int bpp)
}
*eip++ = RETURN;

/* Verify that we didn't overflow (too late!!!) */
if (eip > (copy_row + sizeof(copy_row))) {
SDL_SetError("Copy buffer overflow");
return (-1);
}
#ifdef HAVE_MPROTECT
/* Make the code executable but not writeable */
if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
Expand Down

0 comments on commit db6cbc7

Please sign in to comment.