From c5e550b10d4b61fb5be4b117679bd2cab00420e5 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 1 Dec 2016 15:19:35 +0100 Subject: [PATCH] unix-socket: create socket directory if possible Create the socket directory in the default case. Since we're doing stat+mkdir indicate to Coverity not to worry about the toctou case. --- src/unix-manager.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/unix-manager.c b/src/unix-manager.c index 07f99268c0..cc7af7eb6c 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -143,18 +143,27 @@ int UnixNew(UnixCommand * this) struct stat stat_buf; /* coverity[toctou] */ if (stat(SOCKET_PATH, &stat_buf) != 0) { - SCLogWarning(SC_ERR_INITIALIZATION, - "Unix socket: problem with requested directory in %s: %s", - SOCKET_TARGET, strerror(errno)); - return 0; + int ret; + /* coverity[toctou] */ + ret = mkdir(SOCKET_PATH, S_IRWXU|S_IXGRP|S_IRGRP); + if (ret != 0) { + int err = errno; + if (err != EEXIST) { + SCLogError(SC_ERR_INITIALIZATION, + "Cannot create socket directory %s: %s", + SOCKET_PATH, strerror(err)); + return 0; + } + } else { + SCLogInfo("Created socket directory %s", + SOCKET_PATH); + } } sockettarget = SCStrdup(SOCKET_TARGET); if (unlikely(sockettarget == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate socket name"); return 0; } - - } /* Remove socket file */ -- 2.47.2