file: Provide EF_WITH_CADEF_MAX_ENTRY_SIZE to clean up xditem()

xditem() needs a buffer that can hold entries of any xdumpable table.
It's been 2048 bytes and marked FIXME since day one.  Clean it up so
that if anyone ever goes crazy with entry sizes, we fail an assertion
during startup instead of overrunning the buffer during play.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-01-27 20:57:20 +01:00
parent 9ef4f1bf50
commit 9a6998882a
3 changed files with 16 additions and 4 deletions

View file

@ -27,7 +27,7 @@
* file.h: Describes Empire tables (`files' for historical reasons) * file.h: Describes Empire tables (`files' for historical reasons)
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2005-2012 * Markus Armbruster, 2005-2014
*/ */
#ifndef FILE_H #ifndef FILE_H
@ -130,6 +130,12 @@ struct emptypedstr {
/* Create table file, clobbering any existing file */ /* Create table file, clobbering any existing file */
#define EFF_CREATE bit(16) #define EFF_CREATE bit(16)
/*
* A value larger than any struct empfile member size where member
* cadef is not null.
*/
#define EF_WITH_CADEF_MAX_ENTRY_SIZE 1024
/* /*
* Empire `file types' * Empire `file types'
* These are really table IDs. Some tables are backed by files, some * These are really table IDs. Some tables are backed by files, some

View file

@ -27,7 +27,7 @@
* xdump.c: Extended dump * xdump.c: Extended dump
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2014
*/ */
#include <config.h> #include <config.h>
@ -140,7 +140,7 @@ xditem(struct xdstr *xd, int type, char *arg)
struct castr *ca; struct castr *ca;
struct nstr_item ni; struct nstr_item ni;
int n; int n;
char buf[2048]; /* FIXME buffer size? */ unsigned char buf[EF_WITH_CADEF_MAX_ENTRY_SIZE];
ca = ef_cadef(type); ca = ef_cadef(type);
if (!ca) if (!ca)

View file

@ -27,11 +27,12 @@
* filetable.c: Empire game data file descriptions. * filetable.c: Empire game data file descriptions.
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2005-2013 * Markus Armbruster, 2005-2014
*/ */
#include <config.h> #include <config.h>
#include <assert.h>
#include <stddef.h> #include <stddef.h>
#include "commodity.h" #include "commodity.h"
#include "file.h" #include "file.h"
@ -394,6 +395,11 @@ empfile_init(void)
void void
empfile_fixup(void) empfile_fixup(void)
{ {
struct empfile *ep;
empfile[EF_SECTOR].nent = WORLD_SZ(); empfile[EF_SECTOR].nent = WORLD_SZ();
empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ(); empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ();
for (ep = empfile; ep->uid >= 0; ep++)
assert(!ep->cadef || ep->size <= EF_WITH_CADEF_MAX_ENTRY_SIZE);
} }