redo bspfile to use dynamic allocation for the arrays to avoid buffer

overflows. also fix up the verbosity levels in qfvis.c
This commit is contained in:
Bill Currie 2002-09-18 06:07:38 +00:00
parent ef49e4cf17
commit 599fea0edb
3 changed files with 54 additions and 51 deletions

View file

@ -234,49 +234,49 @@ typedef struct {
// the utilities get to be lazy and just use large static arrays // the utilities get to be lazy and just use large static arrays
extern int nummodels; extern int nummodels;
extern dmodel_t dmodels[MAX_MAP_MODELS]; extern dmodel_t *dmodels;
extern int visdatasize; extern int visdatasize;
extern byte dvisdata[MAX_MAP_VISIBILITY]; extern byte *dvisdata;
extern int lightdatasize; extern int lightdatasize;
extern byte dlightdata[MAX_MAP_LIGHTING]; extern byte *dlightdata;
extern int texdatasize; extern int texdatasize;
extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t) extern byte *dtexdata; // (dmiptexlump_t)
extern int entdatasize; extern int entdatasize;
extern char dentdata[MAX_MAP_ENTSTRING]; extern char *dentdata;
extern int numleafs; extern int numleafs;
extern dleaf_t dleafs[MAX_MAP_LEAFS]; extern dleaf_t *dleafs;
extern int numplanes; extern int numplanes;
extern dplane_t dplanes[MAX_MAP_PLANES]; extern dplane_t *dplanes;
extern int numvertexes; extern int numvertexes;
extern dvertex_t dvertexes[MAX_MAP_VERTS]; extern dvertex_t *dvertexes;
extern int numnodes; extern int numnodes;
extern dnode_t dnodes[MAX_MAP_NODES]; extern dnode_t *dnodes;
extern int numtexinfo; extern int numtexinfo;
extern texinfo_t texinfo[MAX_MAP_TEXINFO]; extern texinfo_t *texinfo;
extern int numfaces; extern int numfaces;
extern dface_t dfaces[MAX_MAP_FACES]; extern dface_t *dfaces;
extern int numclipnodes; extern int numclipnodes;
extern dclipnode_t dclipnodes[MAX_MAP_CLIPNODES]; extern dclipnode_t *dclipnodes;
extern int numedges; extern int numedges;
extern dedge_t dedges[MAX_MAP_EDGES]; extern dedge_t *dedges;
extern int nummarksurfaces; extern int nummarksurfaces;
extern unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES]; extern unsigned short *dmarksurfaces;
extern int numsurfedges; extern int numsurfedges;
extern int dsurfedges[MAX_MAP_SURFEDGES]; extern int *dsurfedges;
void DecompressVis (byte *in, byte *decompressed); void DecompressVis (byte *in, byte *decompressed);
int CompressVis (byte *vis, byte *dest); int CompressVis (byte *vis, byte *dest);

View file

@ -50,49 +50,49 @@ static const char rcsid[] =
#include "QF/sys.h" #include "QF/sys.h"
int nummodels; int nummodels;
dmodel_t dmodels[MAX_MAP_MODELS]; dmodel_t *dmodels;
int visdatasize; int visdatasize;
byte dvisdata[MAX_MAP_VISIBILITY]; byte *dvisdata;
int lightdatasize; int lightdatasize;
byte dlightdata[MAX_MAP_LIGHTING]; byte *dlightdata;
int texdatasize; int texdatasize;
byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t) byte *dtexdata;
int entdatasize; int entdatasize;
char dentdata[MAX_MAP_ENTSTRING]; char *dentdata;
int numleafs; int numleafs;
dleaf_t dleafs[MAX_MAP_LEAFS]; dleaf_t *dleafs;
int numplanes; int numplanes;
dplane_t dplanes[MAX_MAP_PLANES]; dplane_t *dplanes;
int numvertexes; int numvertexes;
dvertex_t dvertexes[MAX_MAP_VERTS]; dvertex_t *dvertexes;
int numnodes; int numnodes;
dnode_t dnodes[MAX_MAP_NODES]; dnode_t *dnodes;
int numtexinfo; int numtexinfo;
texinfo_t texinfo[MAX_MAP_TEXINFO]; texinfo_t *texinfo;
int numfaces; int numfaces;
dface_t dfaces[MAX_MAP_FACES]; dface_t *dfaces;
int numclipnodes; int numclipnodes;
dclipnode_t dclipnodes[MAX_MAP_CLIPNODES]; dclipnode_t *dclipnodes;
int numedges; int numedges;
dedge_t dedges[MAX_MAP_EDGES]; dedge_t *dedges;
int nummarksurfaces; int nummarksurfaces;
unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES]; unsigned short *dmarksurfaces;
int numsurfedges; int numsurfedges;
int dsurfedges[MAX_MAP_SURFEDGES]; int *dsurfedges;
dheader_t *header; dheader_t *header;
dheader_t outheader; dheader_t outheader;
@ -234,7 +234,7 @@ AddLump (int lumpnum, void *data, int len)
} }
static int static int
CopyLump (int lump, void *dest, int size) CopyLump (int lump, void **dest, int size)
{ {
int length, ofs; int length, ofs;
@ -244,7 +244,10 @@ CopyLump (int lump, void *dest, int size)
if (length % size) if (length % size)
Sys_Error ("LoadBSPFile: odd lump size"); Sys_Error ("LoadBSPFile: odd lump size");
memcpy (dest, (byte *) header + ofs, length); *dest = malloc (length);
if (!dest)
Sys_Error ("LoadBSPFile: out of memory");
memcpy (*dest, (byte *) header + ofs, length);
return length / size; return length / size;
} }
@ -265,25 +268,25 @@ LoadBSPFile (const char *filename)
if (header->version != BSPVERSION) if (header->version != BSPVERSION)
Sys_Error ("%s is version %i, not %i", filename, i, BSPVERSION); Sys_Error ("%s is version %i, not %i", filename, i, BSPVERSION);
//FIXME casting to (void**) isn't really portable :(
nummodels = CopyLump (LUMP_MODELS, dmodels, sizeof (dmodel_t)); nummodels = CopyLump (LUMP_MODELS, (void **)&dmodels, sizeof (dmodel_t));
numvertexes = CopyLump (LUMP_VERTEXES, dvertexes, sizeof (dvertex_t)); numvertexes = CopyLump (LUMP_VERTEXES, (void **)&dvertexes, sizeof (dvertex_t));
numplanes = CopyLump (LUMP_PLANES, dplanes, sizeof (dplane_t)); numplanes = CopyLump (LUMP_PLANES, (void **)&dplanes, sizeof (dplane_t));
numleafs = CopyLump (LUMP_LEAFS, dleafs, sizeof (dleaf_t)); numleafs = CopyLump (LUMP_LEAFS, (void **)&dleafs, sizeof (dleaf_t));
numnodes = CopyLump (LUMP_NODES, dnodes, sizeof (dnode_t)); numnodes = CopyLump (LUMP_NODES, (void **)&dnodes, sizeof (dnode_t));
numtexinfo = CopyLump (LUMP_TEXINFO, texinfo, sizeof (texinfo_t)); numtexinfo = CopyLump (LUMP_TEXINFO, (void **)&texinfo, sizeof (texinfo_t));
numclipnodes = CopyLump (LUMP_CLIPNODES, dclipnodes, sizeof (dclipnode_t)); numclipnodes = CopyLump (LUMP_CLIPNODES, (void **)&dclipnodes, sizeof (dclipnode_t));
numfaces = CopyLump (LUMP_FACES, dfaces, sizeof (dface_t)); numfaces = CopyLump (LUMP_FACES, (void **)&dfaces, sizeof (dface_t));
nummarksurfaces = CopyLump (LUMP_MARKSURFACES, dmarksurfaces, nummarksurfaces = CopyLump (LUMP_MARKSURFACES, (void **)&dmarksurfaces,
sizeof (dmarksurfaces[0])); sizeof (dmarksurfaces[0]));
numsurfedges = CopyLump (LUMP_SURFEDGES, dsurfedges, numsurfedges = CopyLump (LUMP_SURFEDGES, (void **)&dsurfedges,
sizeof (dsurfedges[0])); sizeof (dsurfedges[0]));
numedges = CopyLump (LUMP_EDGES, dedges, sizeof (dedge_t)); numedges = CopyLump (LUMP_EDGES, (void **)&dedges, sizeof (dedge_t));
texdatasize = CopyLump (LUMP_TEXTURES, dtexdata, 1); texdatasize = CopyLump (LUMP_TEXTURES, (void **)&dtexdata, 1);
visdatasize = CopyLump (LUMP_VISIBILITY, dvisdata, 1); visdatasize = CopyLump (LUMP_VISIBILITY, (void **)&dvisdata, 1);
lightdatasize = CopyLump (LUMP_LIGHTING, dlightdata, 1); lightdatasize = CopyLump (LUMP_LIGHTING, (void **)&dlightdata, 1);
entdatasize = CopyLump (LUMP_ENTITIES, dentdata, 1); entdatasize = CopyLump (LUMP_ENTITIES, (void **)&dentdata, 1);
free (header); free (header);

View file

@ -370,7 +370,7 @@ void *LeafThread (void *thread)
PortalFlow (portal); PortalFlow (portal);
if (options.verbosity >= 0) if (options.verbosity > 0)
printf ("portal:%4i mightsee:%4i cansee:%4i\n", printf ("portal:%4i mightsee:%4i cansee:%4i\n",
(int) (portal - portals), (int) (portal - portals),
portal->nummightsee, portal->nummightsee,
@ -449,7 +449,7 @@ LeafFlow (int leafnum)
numvis++; numvis++;
// compress the bit string // compress the bit string
if (options.verbosity >= 0) if (options.verbosity > 0)
printf ("leaf %4i : %4i visible\n", leafnum, numvis); printf ("leaf %4i : %4i visible\n", leafnum, numvis);
totalvis += numvis; totalvis += numvis;
@ -524,7 +524,7 @@ CalcPortalVis (void)
LeafThread (0); LeafThread (0);
#endif #endif
if (options.verbosity >= 0) { if (options.verbosity > 0) {
printf ("portalcheck: %i portaltest: %i portalpass: %i\n", printf ("portalcheck: %i portaltest: %i portalpass: %i\n",
c_portalcheck, c_portaltest, c_portalpass); c_portalcheck, c_portaltest, c_portalpass);
printf ("c_vistest: %i c_mighttest: %i\n", c_vistest, c_mighttest); printf ("c_vistest: %i c_mighttest: %i\n", c_vistest, c_mighttest);