Merge pull request #241 from xycaleth/master

Fixed a number of out of bounds accesses.
This commit is contained in:
Timothee "TTimo" Besset 2015-03-08 10:22:26 -05:00
commit 3f58715a04
13 changed files with 38 additions and 18 deletions

View File

@ -68,6 +68,8 @@ void IncDrawVerts(){
}
else if ( numBSPDrawVerts > numBSPDrawVertsBuffer ) {
bspDrawVert_t *newBspDrawVerts;
numBSPDrawVertsBuffer *= 3; // multiply by 1.5
numBSPDrawVertsBuffer /= 2;
@ -75,11 +77,14 @@ void IncDrawVerts(){
numBSPDrawVertsBuffer = MAX_MAP_DRAW_VERTS;
}
bspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer );
newBspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer );
if ( !bspDrawVerts ) {
if ( !newBspDrawVerts ) {
free (bspDrawVerts);
Error( "realloc() failed (IncDrawVerts)" );
}
bspDrawVerts = newBspDrawVerts;
}
memset( bspDrawVerts + ( numBSPDrawVerts - 1 ), 0, sizeof( bspDrawVert_t ) );

View File

@ -185,10 +185,10 @@ static void RadClipWindingEpsilon( radWinding_t *in, vec3_t normal, vec_t dist,
}
/* error check */
if ( front->numVerts > maxPoints || front->numVerts > maxPoints ) {
if ( front->numVerts > maxPoints ) {
Error( "RadClipWindingEpsilon: points exceeded estimate" );
}
if ( front->numVerts > MAX_POINTS_ON_WINDING || front->numVerts > MAX_POINTS_ON_WINDING ) {
if ( front->numVerts > MAX_POINTS_ON_WINDING ) {
Error( "RadClipWindingEpsilon: MAX_POINTS_ON_WINDING" );
}
}
@ -279,7 +279,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
/* multiply by texture color */
if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, rw->verts[ samples ].st, textureColor ) ) {
VectorCopy( si->averageColor, textureColor );
textureColor[ 4 ] = 255.0f;
textureColor[ 3 ] = 255.0f;
}
for ( i = 0; i < 3; i++ )
color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
@ -363,7 +363,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
/* multiply by texture color */
if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, st, textureColor ) ) {
VectorCopy( si->averageColor, textureColor );
textureColor[ 4 ] = 255;
textureColor[ 3 ] = 255;
}
for ( i = 0; i < 3; i++ )
color[ i ] = ( textureColor[ i ] / 255 ) * ( radLuxel[ i ] / 255 );

View File

@ -2104,6 +2104,11 @@ static void FindOutLightmaps( rawLightmap_t *lm ){
/* allocate two new output lightmaps */
numOutLightmaps += 2;
olm = safe_malloc( numOutLightmaps * sizeof( outLightmap_t ) );
if ( !olm )
{
Error( "FindOutLightmaps: Failed to allocate memory.\n" );
}
if ( outLightmaps != NULL && numOutLightmaps > 2 ) {
memcpy( olm, outLightmaps, ( numOutLightmaps - 2 ) * sizeof( outLightmap_t ) );
free( outLightmaps );

View File

@ -279,7 +279,7 @@ int AnalyzeBSP( int argc, char **argv ){
lumpInt = LittleLong( (int) *( (int*) lump ) );
lumpFloat = LittleFloat( (float) *( (float*) lump ) );
memcpy( lumpString, (char*) lump, ( length < 1024 ? length : 1024 ) );
lumpString[ 1024 ] = '\0';
lumpString[ 1023 ] = '\0';
/* print basic lump info */
Sys_Printf( "Lump: %d\n", i );

View File

@ -763,7 +763,7 @@ typedef struct shaderInfo_s
sun_t *sun; /* ydnar */
vec3_t color; /* normalized color */
vec3_t averageColor;
vec4_t averageColor;
byte lightStyle;
qb_t lmMergable; /* ydnar */

View File

@ -791,6 +791,7 @@ static void LoadShaderImages( shaderInfo_t *si ){
ColorNormalize( color, si->color );
}
VectorScale( color, ( 1.0f / count ), si->averageColor );
si->averageColor[ 3 ] = color[ 3 ] / count;
}

View File

@ -740,7 +740,8 @@ static qboolean PointTriangleIntersect( vec3_t pt, vec4_t plane, vec3_t a, vec3_
typedef struct edge_s
{
vec3_t origin, edge;
vec3_t origin;
vec4_t edge;
vec_t length, kingpinLength;
int kingpin;
vec4_t plane;

View File

@ -68,6 +68,8 @@ void IncDrawVerts(){
}
else if ( numBSPDrawVerts > numBSPDrawVertsBuffer ) {
bspDrawVert_t *newBspDrawVerts;
numBSPDrawVertsBuffer *= 3; // multiply by 1.5
numBSPDrawVertsBuffer /= 2;
@ -75,11 +77,14 @@ void IncDrawVerts(){
numBSPDrawVertsBuffer = MAX_MAP_DRAW_VERTS;
}
bspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer );
newBspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer );
if ( !bspDrawVerts ) {
if ( !newBspDrawVerts ) {
free (bspDrawVerts);
Error( "realloc() failed (IncDrawVerts)" );
}
bspDrawVerts = newBspDrawVerts;
}
memset( bspDrawVerts + ( numBSPDrawVerts - 1 ), 0, sizeof( bspDrawVert_t ) );

View File

@ -185,10 +185,10 @@ static void RadClipWindingEpsilon( radWinding_t *in, vec3_t normal, vec_t dist,
}
/* error check */
if ( front->numVerts > maxPoints || front->numVerts > maxPoints ) {
if ( front->numVerts > maxPoints ) {
Error( "RadClipWindingEpsilon: points exceeded estimate" );
}
if ( front->numVerts > MAX_POINTS_ON_WINDING || front->numVerts > MAX_POINTS_ON_WINDING ) {
if ( front->numVerts > MAX_POINTS_ON_WINDING ) {
Error( "RadClipWindingEpsilon: MAX_POINTS_ON_WINDING" );
}
}
@ -279,7 +279,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
/* multiply by texture color */
if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, rw->verts[ samples ].st, textureColor ) ) {
VectorCopy( si->averageColor, textureColor );
textureColor[ 4 ] = 255.0f;
textureColor[ 3 ] = 255.0f;
}
for ( i = 0; i < 3; i++ )
color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
@ -363,7 +363,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
/* multiply by texture color */
if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, st, textureColor ) ) {
VectorCopy( si->averageColor, textureColor );
textureColor[ 4 ] = 255;
textureColor[ 3 ] = 255;
}
for ( i = 0; i < 3; i++ )
color[ i ] = ( textureColor[ i ] / 255 ) * ( radLuxel[ i ] / 255 );

View File

@ -169,7 +169,7 @@ int AnalyzeBSP( int argc, char **argv ){
lumpInt = LittleLong( (int) *( (int*) lump ) );
lumpFloat = LittleFloat( (float) *( (float*) lump ) );
memcpy( lumpString, (char*) lump, ( length < 1024 ? length : 1024 ) );
lumpString[ 1024 ] = '\0';
lumpString[ 1023 ] = '\0';
/* print basic lump info */
Sys_Printf( "Lump: %d\n", i );

View File

@ -743,7 +743,7 @@ typedef struct shaderInfo_s
int sun_done;
vec3_t color; /* normalized color */
vec3_t averageColor;
vec4_t averageColor;
byte lightStyle;
qb_t lmMergable; /* ydnar */

View File

@ -789,10 +789,12 @@ static void LoadShaderImages( shaderInfo_t *si ){
if ( VectorLength( si->color ) <= 0.0f ) {
ColorNormalize( color, si->color );
VectorScale( color, ( 1.0f / count ), si->averageColor );
si->averageColor[ 3 ] = color[ 3 ] / count;
}
else
{
VectorCopy( si->color, si->averageColor );
si->averageColor[ 3 ] = 1.0f;
}
}

View File

@ -743,7 +743,8 @@ static qboolean PointTriangleIntersect( vec3_t pt, vec4_t plane, vec3_t a, vec3_
typedef struct edge_s
{
vec3_t origin, edge;
vec3_t origin;
vec4_t edge;
vec_t length, kingpinLength;
int kingpin;
vec4_t plane;