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:
3
logger.c
3
logger.c
@ -397,6 +397,9 @@ static int LoggerMakeDir(char *path)
|
|||||||
return 0; /* mkdir failed */
|
return 0; /* mkdir failed */
|
||||||
snprintf(buffer, sizeof buffer, "%s", path);
|
snprintf(buffer, sizeof buffer, "%s", path);
|
||||||
lpath = strlen(buffer);
|
lpath = strlen(buffer);
|
||||||
|
/* Discard any trailing slash characters */
|
||||||
|
while (lpath > 0 && buffer[lpath - 1] == '/')
|
||||||
|
buffer[--lpath] = '\0';
|
||||||
do {
|
do {
|
||||||
slash = strrchr(buffer, '/');
|
slash = strrchr(buffer, '/');
|
||||||
if (!slash)
|
if (!slash)
|
||||||
|
@ -118,6 +118,11 @@ static int LogSetup(SConnection * pCon, SicsInterp * pSics, void *pData,
|
|||||||
LoggerChange(logger, period, name);
|
LoggerChange(logger, period, name);
|
||||||
} else {
|
} else {
|
||||||
logger = LoggerMake(name, period, !numeric);
|
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);
|
LoggerSetNumeric(logger, numeric);
|
||||||
SetHdbProperty(node, "logger_name", name);
|
SetHdbProperty(node, "logger_name", name);
|
||||||
cb = MakeHipadabaCallback(LoggerUpdateCallback, logger,
|
cb = MakeHipadabaCallback(LoggerUpdateCallback, logger,
|
||||||
|
Reference in New Issue
Block a user