From 7098518a9bc43378afb5cbf599a074775c1d1d55 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 30 Sep 2019 06:59:05 -0700 Subject: safety: fix type tests that code can subvert. This patch fixes numerous instances of a safety hole which involves the type of a COBJ object being tested to be of a given class using logic that can be subverted by the definition of a like-named struct. Specifically logic like (typeof(obj) == hash_s) is broken, because if a struct type called hash is defined, then the test will yield true for instances of that struct type. Those instances can then be passed into code that only works on COBJ hashes, and relies on this test to reject invalid objects. * ffi.c (make_carray): Replace fragile test with strong one, using new cobjclassp function. * hash.c (hashp): Likewise. * lib.c (class_check): The expression used here for the type test moves into the new function cobjclassp and so is replaced by a call to that function. (cobjclassp): New function. * lib.h (cobjclassp): Declared. * rand.c (random_state_p): Replace fragile test using cobjclassp. * regex.c (char_set_compile): Replace fragile typeof tests for character type with is_chr. (reg_derivative, regexp): Replace fragile test with cobjclassp. * struct.c (struct_type_p): Replace fragile test with cobjclassp. --- lib.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib.h') diff --git a/lib.h b/lib.h index e47b84c6..7c8a582b 100644 --- a/lib.h +++ b/lib.h @@ -1027,6 +1027,7 @@ val length_str_lt(val str, val len); val length_str_le(val str, val len); val cobj(mem_t *handle, val cls_sym, struct cobj_ops *ops); val cobjp(val obj); +val cobjclassp(val obj, val cls_sym); mem_t *cobj_handle(val self, val cobj, val cls_sym); struct cobj_ops *cobj_ops(val self, val cobj, val cls_sym); val cptr(mem_t *ptr); -- cgit v1.2.3