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

@ -671,7 +671,7 @@ symval(struct castr *ca, int i)
{
int type = ca->ca_table;
if (ef_cadef(type) == symbol_ca)
if (type != EF_BAD && ef_cadef(type) == symbol_ca)
/* symbol table, value is in the table */
return ((struct symbol *)ef_ptr(type, i))->value;
/* value is the table index */