From 96a7c04f6a028e2f970362da9a08ea0ca2b0f441 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 7 Jun 2019 22:58:48 +0200 Subject: [PATCH] :art: Template security --- src/parse/template.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/parse/template.c b/src/parse/template.c index 081a4bd6..41cdb0bb 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -69,12 +69,12 @@ ANN static inline size_t tmpl_set(struct tmpl_info* info, const Type t) { return len; } -ANN static size_t template_size(const Env env, struct tmpl_info* info) { +ANN static ssize_t template_size(const Env env, struct tmpl_info* info) { ID_List base = info->cdef->base.tmpl->list; Type_List call = info->call; size_t size = tmpl_set(info, info->cdef->base.type); do { - const Type t = type_decl_resolve(env, call->td); + const Type t = known_type(env, call->td); CHECK_OB(t) size += tmpl_set(info, t); } while((call = call->next) && (base = base->next) && ++size); @@ -103,11 +103,13 @@ ANEW ANN static Symbol template_id(const Env env, const Class_Def c, const Type_ struct tmpl_info info = { .cdef=c, .call=call }; vector_init(&info.type); vector_init(&info.size); - char name[template_size(env, &info)]; - template_name(&info, name); + ssize_t sz = template_size(env, &info); + char name[sz]; + if(sz > GW_ERROR) + template_name(&info, name); vector_release(&info.type); vector_release(&info.size); - return insert_symbol(name); + return sz > GW_ERROR ? insert_symbol(name) : NULL; } ANN m_bool template_match(ID_List base, Type_List call) { @@ -117,6 +119,7 @@ ANN m_bool template_match(ID_List base, Type_List call) { ANN static Class_Def template_class(const Env env, const Class_Def def, const Type_List call) { const Symbol name = template_id(env, def, call); + CHECK_OO(name) if(env->class_def && name == insert_symbol(env->class_def->name)) return env->class_def->e->def; const Type t = nspc_lookup_type1(env->curr, name); @@ -157,6 +160,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { if(template_match(t->e->def->base.tmpl->list, type->types) < 0) ERR_O(type->xid->pos, "invalid template types number") const Class_Def a = template_class(env, t->e->def, type->types); + CHECK_OO(a) SET_FLAG(a, ref); if(a->base.type) return a->base.type; -- 2.43.0