SICS-819 Fix SICS crash in logsetup

Directory creation involving path creation failed because the path has
a trailing slash. After creating the directory of the full path, SICS
tried to create the path again with the trailing slash - it failed.

When logger creation failed, SICS registered the callback with NULL. This
was dereferenced in the hipadaba callback.

Suppress trailing slashes in directory path creation. Do not register
the callback if the creation failed.
This commit is contained in:
Douglas Clowes
2015-01-23 09:18:14 +11:00
parent 18456d2af8
commit 86e1f7b7cf
2 changed files with 8 additions and 0 deletions

View File

@ -397,6 +397,9 @@ static int LoggerMakeDir(char *path)
return 0; /* mkdir failed */
snprintf(buffer, sizeof buffer, "%s", path);
lpath = strlen(buffer);
/* Discard any trailing slash characters */
while (lpath > 0 && buffer[lpath - 1] == '/')
buffer[--lpath] = '\0';
do {
slash = strrchr(buffer, '/');
if (!slash)

View File

@ -118,6 +118,11 @@ static int LogSetup(SConnection * pCon, SicsInterp * pSics, void *pData,
LoggerChange(logger, period, name);
} else {
logger = LoggerMake(name, period, !numeric);
/* If that failed, we cannot continue - it crashes in the callback */
if (logger == NULL) {
SCPrintf(pCon, eError, "ERROR: logger %s not created", argv[1]);
return 0;
}
LoggerSetNumeric(logger, numeric);
SetHdbProperty(node, "logger_name", name);
cb = MakeHipadabaCallback(LoggerUpdateCallback, logger,