From 26c8b502e2d7c2e66f24fa9eff9a70b2fb8f76ce Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 6 Feb 2026 15:55:14 +0100 Subject: [PATCH] cppcheck: fix null ptr dereference --- client/src/cmdscript.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/src/cmdscript.c b/client/src/cmdscript.c index cc1d4000a..f80210897 100644 --- a/client/src/cmdscript.c +++ b/client/src/cmdscript.c @@ -163,6 +163,10 @@ static int split(char *str, char **arr) { int len = end_index - begin_index; char *tmp = calloc(len + 1, sizeof(char)); + if (tmp == NULL) { + PrintAndLogEx(ERR, "Memory allocation failed"); + return -1; + } memcpy(tmp, &str[begin_index], len); arr[word_cnt++] = tmp; begin_index = end_index; @@ -457,6 +461,11 @@ static int CmdScriptRun(const char *Cmd) { char *argv[FILE_PATH_SIZE]; argv[0] = script_path; int argc = split(arguments, &argv[1]); + if (argc < 0) { + PrintAndLogEx(ERR, "Failed to parse script arguments"); + free(script_path); + return PM3_ESOFT; + } #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 10 wchar_t *py_args[argc + 1]; for (int i = 0; i <= argc; i++) {