Skip to content

Commit f71c4fd

Browse files
authored
Merge pull request #336 from toxieainc/master
Add some potential out-of-bounds access prevention and wrong pixel wrapping
2 parents fb76ba8 + dfcbb12 commit f71c4fd

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

engine/openbor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44341,7 +44341,7 @@ void spawnplayer(int index)
4434144341
//////////////////checking holes/ walls///////////////////////////////////
4434244342
for(xc = 0; xc < videomodes.hRes / 4; xc++)
4434344343
{
44344-
if(p.position.x > videomodes.hRes)
44344+
if(p.position.x >= videomodes.hRes)
4434544345
{
4434644346
p.position.x -= videomodes.hRes;
4434744347
}

engine/openborscript.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16156,7 +16156,7 @@ HRESULT openbor_getgfxproperty(ScriptVariant **varlist , ScriptVariant **pretvar
1615616156
{
1615716157
case bitmap_magic: //As long as the two structures are identical...
1615816158
case screen_magic:
16159-
if(x < 0 || x >= screen->width || y < 0 || y >= screen->height)
16159+
if((unsigned)x >= (unsigned)screen->width || (unsigned)y >= (unsigned)screen->height) // includes checks for <0
1616016160
{
1616116161
v = 0;
1616216162
}
@@ -16180,7 +16180,7 @@ HRESULT openbor_getgfxproperty(ScriptVariant **varlist , ScriptVariant **pretvar
1618016180
}
1618116181
break;
1618216182
case sprite_magic:
16183-
if(x < 0 || x >= sprite->width || y < 0 || y >= sprite->height)
16183+
if((unsigned)x >= (unsigned)sprite->width || (unsigned)y >= (unsigned)sprite->height) // includes checks for <0
1618416184
{
1618516185
v = 0;
1618616186
}

engine/source/gamelib/draw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void _putpixel(int x, int y, int colour, s_screen *screen, int alpha)
270270
{
271271
int pixind;
272272
unsigned char *lut;
273-
if((unsigned)x > screen->width || (unsigned)y > screen->height)
273+
if((unsigned)x >= (unsigned)screen->width || (unsigned)y >= (unsigned)screen->height)
274274
{
275275
return;
276276
}

engine/source/gamelib/draw16.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void _putpixel16(unsigned x, unsigned y, unsigned short colour, s_screen *screen
274274
int pixind;
275275
unsigned short *data ;
276276
unsigned short(*blendfp)(unsigned short, unsigned short);
277-
if(x > screen->width || y > screen->height)
277+
if(x >= (unsigned)screen->width || y >= (unsigned)screen->height)
278278
{
279279
return;
280280
}
@@ -283,5 +283,3 @@ void _putpixel16(unsigned x, unsigned y, unsigned short colour, s_screen *screen
283283
blendfp = getblendfunction16(alpha);
284284
__putpixel16(data);
285285
}
286-
287-

engine/source/gamelib/draw32.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void _putpixel32(unsigned x, unsigned y, unsigned colour, s_screen *screen, int
277277
int pixind;
278278
unsigned *data ;
279279
unsigned(*blendfp)(unsigned, unsigned);
280-
if(x > screen->width || y > screen->height)
280+
if(x >= (unsigned)screen->width || y >= (unsigned)screen->height)
281281
{
282282
return;
283283
}
@@ -287,5 +287,3 @@ void _putpixel32(unsigned x, unsigned y, unsigned colour, s_screen *screen, int
287287
blendfp = getblendfunction32(alpha);
288288
__putpixel32(data);
289289
}
290-
291-

0 commit comments

Comments
 (0)