add sanity check that pid file is not null

pull/587/head
JacobBarthelmeh 2023-09-20 16:32:50 -06:00
parent c349510cc3
commit 827d901f52
1 changed files with 11 additions and 9 deletions

View File

@ -1452,16 +1452,18 @@ void wolfSSHD_ConfigSavePID(const WOLFSSHD_CONFIG* conf)
FILE* f;
char buf[12]; /* large enough to hold 'int' type with null terminator */
if (conf->pidFile != NULL) {
WMEMSET(buf, 0, sizeof(buf));
if (WFOPEN(NULL, &f, conf->pidFile, "wb") == 0) {
#ifndef WIN32
#ifndef WIN32
WSNPRINTF(buf, sizeof(buf), "%d", getpid());
#else
#else
WSNPRINTF(buf, sizeof(buf), "%d", _getpid());
#endif
#endif
WFWRITE(NULL, buf, 1, WSTRLEN(buf), f);
WFCLOSE(NULL, f);
}
}
}
#endif /* WOLFSSH_SSHD */