From 077ab4cbd107f6e685bcb96b73349962b1ca9d58 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 25 May 2014 22:54:56 -0500 Subject: [PATCH] Fix OOB access in CM_EdgePlaneNum without erroring in CM_GridPlane I changed warning to error in 9d74227559d46b85d0c43d395cd280d3de7ae8f4, which broke JA's mp/ctf4 map and probably others. --- code/qcommon/cm_patch.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/code/qcommon/cm_patch.c b/code/qcommon/cm_patch.c index 3a4e37cc..3cd7bcaf 100644 --- a/code/qcommon/cm_patch.c +++ b/code/qcommon/cm_patch.c @@ -607,7 +607,7 @@ static int CM_GridPlane( int gridPlanes[MAX_GRID_SIZE][MAX_GRID_SIZE][2], int i, } // should never happen - Com_Error( ERR_DROP, "CM_GridPlane unresolvable" ); + Com_Printf( "WARNING: CM_GridPlane unresolvable\n" ); return -1; } @@ -626,6 +626,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i][j]; p2 = grid->points[i+1][j]; p = CM_GridPlane( gridPlanes, i, j, 0 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p1, p2, up ); @@ -633,6 +636,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i][j+1]; p2 = grid->points[i+1][j+1]; p = CM_GridPlane( gridPlanes, i, j, 1 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p2, p1, up ); @@ -640,6 +646,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i][j]; p2 = grid->points[i][j+1]; p = CM_GridPlane( gridPlanes, i, j, 1 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p2, p1, up ); @@ -647,6 +656,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i+1][j]; p2 = grid->points[i+1][j+1]; p = CM_GridPlane( gridPlanes, i, j, 0 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p1, p2, up ); @@ -654,6 +666,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i+1][j+1]; p2 = grid->points[i][j]; p = CM_GridPlane( gridPlanes, i, j, 0 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p1, p2, up ); @@ -661,6 +676,9 @@ static int CM_EdgePlaneNum( cGrid_t *grid, int gridPlanes[MAX_GRID_SIZE][MAX_GRI p1 = grid->points[i][j]; p2 = grid->points[i+1][j+1]; p = CM_GridPlane( gridPlanes, i, j, 1 ); + if ( p == -1 ) { + return -1; + } VectorMA( p1, 4, planes[ p ].plane, up ); return CM_FindPlane( p1, p2, up );