diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-02-20 07:10:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-02-20 07:10:13 -0800 |
commit | aa37cca2a1e8bc9f347b5b077d4aa66d5fa3292b (patch) | |
tree | 15fdb00ef1899801b80e6b341c344fbfe159fc87 | |
parent | 2a94d23de4080a1668d2cbbb6db2756b4185bf00 (diff) | |
download | txr-aa37cca2a1e8bc9f347b5b077d4aa66d5fa3292b.tar.gz txr-aa37cca2a1e8bc9f347b5b077d4aa66d5fa3292b.tar.bz2 txr-aa37cca2a1e8bc9f347b5b077d4aa66d5fa3292b.zip |
Fix lack of robustness in struct module.
The symbolp test is too weak before calling lookup_slot,
because nil satisfies it, but lookup_slot dereferences
the symbol pointer to access its slot cache.
One of many test cases: parsing #S(time nil nil) segfaults.
* struct.c (slot, maybe_slot, slotset, uslot_fun, umethod_fun,
umethod_args_fun): Check that sym isn't nil before looking it
up as a slot.
-rw-r--r-- | struct.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -859,7 +859,7 @@ val slot(val strct, val sym) const val self = lit("slot"); struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot_load(strct, si, sym); if (!nullocp(ptr)) return deref(ptr); @@ -873,7 +873,7 @@ val maybe_slot(val strct, val sym) const val self = lit("slot"); struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot_load(strct, si, sym); if (!nullocp(ptr)) return deref(ptr); @@ -887,7 +887,7 @@ val slotset(val strct, val sym, val newval) const val self = lit("slotset"); struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot(strct, si, sym); if (!nullocp(ptr)) { if (!si->dirty) { @@ -1213,7 +1213,7 @@ static val uslot_fun(val sym, val strct) val self = lit("uslot"); struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot(strct, si, sym); if (!nullocp(ptr)) return deref(ptr); @@ -1239,7 +1239,7 @@ static val umethod_fun(val sym, struct args *args) struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot(strct, si, sym); if (!nullocp(ptr)) return generic_funcall(deref(ptr), args); @@ -1269,7 +1269,7 @@ static val umethod_args_fun(val env, struct args *args) struct struct_inst *si = struct_handle(strct, self); - if (symbolp(sym)) { + if (sym && symbolp(sym)) { loc ptr = lookup_slot(strct, si, sym); if (!nullocp(ptr)) return generic_funcall(deref(ptr), args_call); |