Provide proper ca_table for carrier unit# selectors

Makes ef_verify() check carrier UIDs are sane.  Partially protects
unit_cargo_init(), which oopses on bad carriers.

This has become possible only since commit 64a53c90 (v4.3.17) set
their values to -1 in newly created units.  Before, they were zero in
units that had never been used, and a proper ca_table would have made
ef_verify() fail when unit#0 didn't exist.

The only unit# selectors left without a proper ca_table are ship's
follow, lost's id and trade's unitid.  Document why.
This commit is contained in:
Markus Armbruster 2011-04-25 07:45:20 +02:00
parent 54fa510425
commit 221268e0e1

View file

@ -69,7 +69,7 @@ static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
static void *nsc_lchr(struct valstr *, struct natstr *, void *); static void *nsc_lchr(struct valstr *, struct natstr *, void *);
static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *); static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *);
/* Ugly hack to improve legibility by avoid long lines */ /* Ugly hacks to avoid illegibly long lines */
#define fldoff(fld) offsetof(CURSTR, fld) #define fldoff(fld) offsetof(CURSTR, fld)
#define empobjoff(fld) offsetof(struct empobj, fld) #define empobjoff(fld) offsetof(struct empobj, fld)
@ -249,6 +249,7 @@ struct castr ship_ca[] = {
{"access", fldoff(shp_access), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"access", fldoff(shp_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
{"mquota", fldoff(shp_mobquota), NSC_UCHAR, 0, NULL, EF_BAD, 0}, {"mquota", fldoff(shp_mobquota), NSC_UCHAR, 0, NULL, EF_BAD, 0},
{"path", fldoff(shp_path), NSC_STRINGY, MAXSHPPATH, NULL, EF_BAD, 0}, {"path", fldoff(shp_path), NSC_STRINGY, MAXSHPPATH, NULL, EF_BAD, 0},
/* follow can point to dead ship; avoid ca_table for now */
{"follow", fldoff(shp_follow), NSC_INT, 0, NULL, EF_BAD, 0}, {"follow", fldoff(shp_follow), NSC_INT, 0, NULL, EF_BAD, 0},
{"name", fldoff(shp_name), NSC_STRINGY, MAXSHPNAMLEN, NULL, {"name", fldoff(shp_name), NSC_STRINGY, MAXSHPNAMLEN, NULL,
EF_BAD, 0}, EF_BAD, 0},
@ -300,8 +301,8 @@ struct castr plane_ca[] = {
NSC_GENITEM(EF_PLANE, EF_PLANE_CHR), NSC_GENITEM(EF_PLANE, EF_PLANE_CHR),
{"wing", fldoff(pln_wing), NSC_STRINGY, 1, NULL, EF_BAD, 0}, {"wing", fldoff(pln_wing), NSC_STRINGY, 1, NULL, EF_BAD, 0},
{"range", fldoff(pln_range), NSC_UCHAR, 0, NULL, EF_BAD, 0}, {"range", fldoff(pln_range), NSC_UCHAR, 0, NULL, EF_BAD, 0},
{"ship", fldoff(pln_ship), NSC_INT, 0, NULL, EF_BAD, 0}, {"ship", fldoff(pln_ship), NSC_INT, 0, NULL, EF_SHIP, 0},
{"land", fldoff(pln_land), NSC_INT, 0, NULL, EF_BAD, 0}, {"land", fldoff(pln_land), NSC_INT, 0, NULL, EF_LAND, 0},
{"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0},
{"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL, {"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL,
EF_PLANE_FLAGS, NSC_BITS}, EF_PLANE_FLAGS, NSC_BITS},
@ -340,7 +341,7 @@ struct castr land_ca[] = {
#define CURSTR struct lndstr #define CURSTR struct lndstr
NSC_GENITEM(EF_LAND, EF_LAND_CHR), NSC_GENITEM(EF_LAND, EF_LAND_CHR),
{"army", fldoff(lnd_army), NSC_STRINGY, 1, NULL, EF_BAD, 0}, {"army", fldoff(lnd_army), NSC_STRINGY, 1, NULL, EF_BAD, 0},
{"ship", fldoff(lnd_ship), NSC_INT, 0, NULL, EF_BAD, 0}, {"ship", fldoff(lnd_ship), NSC_INT, 0, NULL, EF_SHIP, 0},
{"harden", fldoff(lnd_harden), NSC_CHAR, 0, NULL, EF_BAD, 0}, {"harden", fldoff(lnd_harden), NSC_CHAR, 0, NULL, EF_BAD, 0},
{"retreat", fldoff(lnd_retreat), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"retreat", fldoff(lnd_retreat), NSC_SHORT, 0, NULL, EF_BAD, 0},
{"rflags", fldoff(lnd_rflags), NSC_INT, 0, NULL, {"rflags", fldoff(lnd_rflags), NSC_INT, 0, NULL,
@ -350,7 +351,7 @@ struct castr land_ca[] = {
{"pstage", fldoff(lnd_pstage), NSC_SHORT, 0, NULL, {"pstage", fldoff(lnd_pstage), NSC_SHORT, 0, NULL,
EF_PLAGUE_STAGES, NSC_DEITY}, EF_PLAGUE_STAGES, NSC_DEITY},
{"ptime", fldoff(lnd_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY}, {"ptime", fldoff(lnd_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
{"land", fldoff(lnd_land), NSC_INT, 0, NULL, EF_BAD, 0}, {"land", fldoff(lnd_land), NSC_INT, 0, NULL, EF_LAND, 0},
{"access", fldoff(lnd_access), NSC_SHORT, 0, NULL, EF_BAD, 0}, {"access", fldoff(lnd_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
{"att", 0, NSC_DOUBLE, 0, nsc_lnd_att, EF_BAD, NSC_EXTRA}, {"att", 0, NSC_DOUBLE, 0, nsc_lnd_att, EF_BAD, NSC_EXTRA},
{"def", 0, NSC_DOUBLE, 0, nsc_lnd_def, EF_BAD, NSC_EXTRA}, {"def", 0, NSC_DOUBLE, 0, nsc_lnd_def, EF_BAD, NSC_EXTRA},
@ -406,7 +407,7 @@ struct castr lchr_ca[] = {
struct castr nuke_ca[] = { struct castr nuke_ca[] = {
#define CURSTR struct nukstr #define CURSTR struct nukstr
NSC_GENITEM(EF_NUKE, EF_NUKE_CHR), NSC_GENITEM(EF_NUKE, EF_NUKE_CHR),
{"plane", fldoff(nuk_plane), NSC_INT, 0, NULL, EF_BAD, 0}, {"plane", fldoff(nuk_plane), NSC_INT, 0, NULL, EF_PLANE, 0},
{NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0} {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
#undef CURSTR #undef CURSTR
}; };
@ -487,6 +488,7 @@ struct castr lost_ca[] = {
EF_BAD, 0}, EF_BAD, 0},
{"owner", fldoff(lost_owner), NSC_NATID, 0, NULL, EF_NATION, 0}, {"owner", fldoff(lost_owner), NSC_NATID, 0, NULL, EF_NATION, 0},
{"type", fldoff(lost_type), NSC_CHAR, 0, NULL, EF_TABLE, 0}, {"type", fldoff(lost_type), NSC_CHAR, 0, NULL, EF_TABLE, 0},
/* id's ca_table given by type, but can't express that: */
{"id", fldoff(lost_id), NSC_INT, 0, NULL, EF_BAD, 0}, {"id", fldoff(lost_id), NSC_INT, 0, NULL, EF_BAD, 0},
{"x", fldoff(lost_x), NSC_XCOORD, 0, NULL, EF_BAD, 0}, {"x", fldoff(lost_x), NSC_XCOORD, 0, NULL, EF_BAD, 0},
{"y", fldoff(lost_y), NSC_YCOORD, 0, NULL, EF_BAD, 0}, {"y", fldoff(lost_y), NSC_YCOORD, 0, NULL, EF_BAD, 0},
@ -522,6 +524,7 @@ struct castr trade_ca[] = {
EF_BAD, NSC_EXTRA}, EF_BAD, NSC_EXTRA},
{"owner", fldoff(trd_owner), NSC_NATID, 0, NULL, EF_NATION, 0}, {"owner", fldoff(trd_owner), NSC_NATID, 0, NULL, EF_NATION, 0},
{"type", fldoff(trd_type), NSC_CHAR, 0, NULL, EF_TABLE, 0}, {"type", fldoff(trd_type), NSC_CHAR, 0, NULL, EF_TABLE, 0},
/* unitid's ca_table given by type, but can't express that: */
{"unitid", fldoff(trd_unitid), NSC_INT, 0, NULL, EF_BAD, 0}, {"unitid", fldoff(trd_unitid), NSC_INT, 0, NULL, EF_BAD, 0},
{"price", fldoff(trd_price), NSC_LONG, 0, NULL, EF_BAD, 0}, {"price", fldoff(trd_price), NSC_LONG, 0, NULL, EF_BAD, 0},
{"maxbidder", fldoff(trd_maxbidder), NSC_INT, 0, NULL, EF_NATION, 0}, {"maxbidder", fldoff(trd_maxbidder), NSC_INT, 0, NULL, EF_NATION, 0},