From 45bbe274e9f13f935a5e31ba2e7cc46e26495e7f Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 12 Feb 2020 11:58:32 +0000 Subject: [PATCH] Error case for NULL arg causing segfault in iocshPersistentString --- modules/libcom/src/iocsh/iocsh.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/libcom/src/iocsh/iocsh.cpp b/modules/libcom/src/iocsh/iocsh.cpp index 8e4d365f9..2341c9b83 100644 --- a/modules/libcom/src/iocsh/iocsh.cpp +++ b/modules/libcom/src/iocsh/iocsh.cpp @@ -314,13 +314,18 @@ cvtArg (const char *filename, int lineno, char *arg, iocshArgBuf *argBuf, break; case iocshArgPersistentString: - argBuf->sval = (char *) malloc(strlen(arg) + 1); - if (argBuf->sval == NULL) { - showError(filename, lineno, "Out of memory"); + if (arg != NULL) { + argBuf->sval = (char *) malloc(strlen(arg) + 1); + if (argBuf->sval == NULL) { + showError(filename, lineno, "Out of memory"); + return 0; + } + strcpy(argBuf->sval, arg); + break; + } else { + showError(filename, lineno, "Unable to copy as provided arg was NULL"); return 0; } - strcpy(argBuf->sval, arg); - break; case iocshArgPdbbase: /* Argument must be missing or 0 or pdbbase */