From 827d901f52b086a05f88c102164ada58e40e28b1 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Wed, 20 Sep 2023 16:32:50 -0600 Subject: [PATCH] add sanity check that pid file is not null --- apps/wolfsshd/configuration.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/wolfsshd/configuration.c b/apps/wolfsshd/configuration.c index 60a8054a..86245ba5 100644 --- a/apps/wolfsshd/configuration.c +++ b/apps/wolfsshd/configuration.c @@ -1452,15 +1452,17 @@ void wolfSSHD_ConfigSavePID(const WOLFSSHD_CONFIG* conf) FILE* f; char buf[12]; /* large enough to hold 'int' type with null terminator */ - WMEMSET(buf, 0, sizeof(buf)); - if (WFOPEN(NULL, &f, conf->pidFile, "wb") == 0) { -#ifndef WIN32 - WSNPRINTF(buf, sizeof(buf), "%d", getpid()); -#else - WSNPRINTF(buf, sizeof(buf), "%d", _getpid()); -#endif - WFWRITE(NULL, buf, 1, WSTRLEN(buf), f); - WFCLOSE(NULL, f); + if (conf->pidFile != NULL) { + WMEMSET(buf, 0, sizeof(buf)); + if (WFOPEN(NULL, &f, conf->pidFile, "wb") == 0) { + #ifndef WIN32 + WSNPRINTF(buf, sizeof(buf), "%d", getpid()); + #else + WSNPRINTF(buf, sizeof(buf), "%d", _getpid()); + #endif + WFWRITE(NULL, buf, 1, WSTRLEN(buf), f); + WFCLOSE(NULL, f); + } } }