iocsh: Protect echo and cd from NULL arguments

This commit is contained in:
Andrew Johnson
2014-10-31 12:19:09 -05:00
parent 09ff608ca9
commit 647bd334ae

View File

@@ -59,7 +59,10 @@ static void echoCallFunc(const iocshArgBuf *args)
{
char *str = args[0].sval;
dbTranslateEscape(str, str); /* in-place is safe */
if (str)
dbTranslateEscape(str, str); /* in-place is safe */
else
str = "";
printf("%s\n", str);
}
@@ -69,9 +72,8 @@ static const iocshArg * const chdirArgs[1] = {&chdirArg0};
static const iocshFuncDef chdirFuncDef = {"cd",1,chdirArgs};
static void chdirCallFunc(const iocshArgBuf *args)
{
int status;
status = chdir(args[0].sval);
if (status) {
if (args[0].sval == NULL ||
chdir(args[0].sval)) {
fprintf(stderr, "Invalid directory path, ignored\n");
}
}