From e67a56eb600a1ff66534a20ba14cd07cc767a5ae Mon Sep 17 00:00:00 2001 From: randomdude999 Date: Thu, 18 Jan 2024 08:24:04 +0200 Subject: [PATCH] check macro call syntax more closes #295 --- src/asar/macro.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/asar/macro.cpp b/src/asar/macro.cpp index 3f9b8bd2..1747e291 100644 --- a/src/asar/macro.cpp +++ b/src/asar/macro.cpp @@ -130,11 +130,15 @@ void callmacro(const char * data) thismacro = macros.find(line); char * endpar=startpar+strlen(startpar)-1; //confirmqpar requires that all parentheses are matched, and a starting one exists, therefore it is harmless to not check for nullptrs - if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_declaration); + if (*endpar != ')') asar_throw_error(0, error_type_block, error_id_broken_macro_usage); *endpar=0; autoptr args; int numargs=0; - if (*startpar) args=(const char* const*)qpsplit(startpar, ',', &numargs); + if (*startpar) { + args=(const char* const*)qpsplit(startpar, ',', &numargs); + // qpsplit returns a nullptr when the input is broken, e.g. closing paren before opening or whatnot + if(args == nullptr) asar_throw_error(0, error_type_block, error_id_broken_macro_usage); + } if (numargs != thismacro->numargs && !thismacro->variadic) asar_throw_error(1, error_type_block, error_id_macro_wrong_num_params); // RPG Hacker: -1, because the ... is also counted as an argument, yet we want it to be entirely optional. if (numargs < thismacro->numargs - 1 && thismacro->variadic) asar_throw_error(1, error_type_block, error_id_macro_wrong_min_params);