Skip to content

Commit

Permalink
Prevent out of bounds map manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Sep 27, 2020
1 parent 7f98932 commit 89dbdb4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,7 @@ static bool mx_portal_in( map &m, const tripoint &abs_sub )
case 2: {
m.add_field( portal_location, field_type_id( "fd_fatigue" ), 3 );
for( const auto &loc : m.points_in_radius( portal_location, 5 ) ) {
m.place_spawns( GROUP_NETHER_PORTAL, 15, loc.xy() + point( -5, -5 ), loc.xy() + point( 5, 5 ), 1,
true );
m.place_spawns( GROUP_NETHER_PORTAL, 15, loc.xy(), loc.xy(), 1, true );
}
break;
}
Expand All @@ -1720,7 +1719,7 @@ static bool mx_portal_in( map &m, const tripoint &abs_sub )
//Radiation from the portal killed the vegetation
case 4: {
m.add_field( portal_location, field_type_id( "fd_fatigue" ), 3 );
const int rad = 10;
const int rad = 5;
for( int i = p.x - rad; i <= p.x + rad; i++ ) {
for( int j = p.y - rad; j <= p.y + rad; j++ ) {
if( trig_dist( p, point( i, j ) ) + rng( 0, 3 ) <= rad ) {
Expand All @@ -1735,7 +1734,7 @@ static bool mx_portal_in( map &m, const tripoint &abs_sub )
//Lava seams originating from the portal
case 5: {
if( abs_sub.z <= 0 ) {
point p1( rng( 0, SEEX - 3 ), rng( 0, SEEY - 3 ) );
point p1( rng( 1, SEEX - 3 ), rng( 1, SEEY - 3 ) );
point p2( rng( SEEX, SEEX * 2 - 3 ), rng( SEEY, SEEY * 2 - 3 ) );
// Pick a random cardinal direction to also spawn lava in
// This will make the lava a single connected line, not just on diagonals
Expand Down Expand Up @@ -1782,10 +1781,12 @@ static bool mx_portal_in( map &m, const tripoint &abs_sub )
//Mi-go went through the portal and began constructing their base of operations
m.add_field( portal_location, field_type_id( "fd_fatigue" ), 3 );
for( const auto &loc : m.points_in_radius( portal_location, 5 ) ) {
m.place_spawns( GROUP_MI_GO_CAMP_OM, 30, loc.xy() + point( -5, -5 ), loc.xy() + point( 5, 5 ), 1,
true );
m.place_spawns( GROUP_MI_GO_CAMP_OM, 30, loc.xy(), loc.xy(), 1, true );
}
const point pos( p + point( rng( -5, 5 ), rng( -5, 5 ) ) );
point pos;
do {
pos = p + point( rng( -5, 5 ), rng( -5, 5 ) );
} while( pos.x >= 1 && pos.y >= 1 && pos.x < SEEX * 2 - 1 && pos.y < SEEY * 2 - 1 );

This comment has been minimized.

Copy link
@irwiss

irwiss Oct 24, 2020

Contributor

Is the loop condition accidentally inverted here?

I've had game freeze here, debugger shows 10,10,X for the function input coords and main thread spinning in this loop

This comment has been minimized.

Copy link
@ZhilkinSerg

ZhilkinSerg Nov 25, 2020

Contributor

Yeah, looks like this - had freeze here too.

circle( &m, ter_id( "t_wall_resin" ), pos, 6 );
rough_circle( &m, ter_id( "t_floor_resin" ), pos, 5 );
break;
Expand Down

0 comments on commit 89dbdb4

Please sign in to comment.