From 105e5754b360d470a3da2cded6442d30c486b3cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 9 Dec 2019 22:20:54 +0100 Subject: [PATCH] :art: prevent did_you_mean from overflow --- include/env/nspc.h | 5 +++++ src/parse/did_you_mean.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/include/env/nspc.h b/include/env/nspc.h index 19c1eb8c..c0e3546a 100644 --- a/include/env/nspc.h +++ b/include/env/nspc.h @@ -67,6 +67,11 @@ describe_nspc_func(Func, func) ANN void did_you_mean_nspc(const Nspc, const char*); ANN void did_you_mean_type(const Type, const char*); + +#define DID_YOU_MEAN_LIMIT 128 +#define did_you_mean_nspc(a, b) if(strlen(b) < DID_YOU_MEAN_LIMIT) did_you_mean_nspc(a,b); +#define did_you_mean_type(a, b) if(strlen(b) < DID_YOU_MEAN_LIMIT) did_you_mean_type(a,b); + ANN static inline void nspc_allocdata(MemPool mp, const Nspc nspc) { if(nspc->info->class_data_size) // nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size); diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index 83e81bbb..a9ae6956 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -43,6 +43,7 @@ ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) { } } +#undef did_you_mean_nspc ANN void did_you_mean_nspc(Nspc nspc, const char* name) { struct Vector_ v; vector_init(&v); @@ -53,6 +54,7 @@ ANN void did_you_mean_nspc(Nspc nspc, const char* name) { vector_release(&v); } +#undef did_you_mean_type ANN void did_you_mean_type(Type type, const char* name) { Type t = type; struct Vector_ v; -- 2.43.0