Fix misuse of ef_cadef(EF_BAD)

ef_elt_by_name(), xdprval_sym() and symval() checked whether a file
type T is a symbol table by comparing ef_cadef(T) to symbol_ca, even
though T may be EF_BAD.  Before commit 50cfdcb5, ef_cadef(EF_BAD)
accessed empfile[] out of bounds, which could conceivably crash or
somehow happen to yield symbol_ca.  Since then, it oopses and returns
null.

Fix by testing the file type before calling ef_cadef().
This commit is contained in:
Markus Armbruster 2008-09-01 10:29:01 -04:00
parent 50cfdcb5a7
commit d929aa8b82
3 changed files with 7 additions and 4 deletions

View file

@ -197,10 +197,10 @@ xdprsym(struct xdstr *xd, int key, int type, char *sep)
* CA describes the field from which the value was fetched.
*/
static char *
xdprval_sym(struct xdstr *xd, struct valstr *val, struct castr *ca, char *sep)
xdprval_sym(struct xdstr *xd, struct valstr *val, struct castr *ca,
char *sep)
{
unsigned long bit;
struct castr *ca_sym = ef_cadef(ca->ca_table);
if (CANT_HAPPEN(val->val_cat != NSC_VAL)) {
xd->pr("%snil", sep);
@ -208,7 +208,7 @@ xdprval_sym(struct xdstr *xd, struct valstr *val, struct castr *ca, char *sep)
}
if (!xd->human || val->val_type != NSC_LONG
|| ca->ca_table == EF_BAD || ca_sym != symbol_ca)
|| ca->ca_table == EF_BAD || ef_cadef(ca->ca_table) != symbol_ca)
return xdprval_nosym(xd, val, sep);
if (ca->ca_flags & NSC_BITS) {