From 86e1f7b7cf692335e69dd0ad2a6ebf0a31b290b0 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 23 Jan 2015 09:18:14 +1100 Subject: [PATCH] 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. --- logger.c | 3 +++ logsetup.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/logger.c b/logger.c index 37d0d631..bcf7c682 100644 --- a/logger.c +++ b/logger.c @@ -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) diff --git a/logsetup.c b/logsetup.c index a8394b97..aceb023e 100644 --- a/logsetup.c +++ b/logsetup.c @@ -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,