You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2019/09/30 12:04:02 UTC
[commons-daemon] branch master updated: Fix possible unsafe code
warnings reported with VS 2017
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
The following commit(s) were added to refs/heads/master by this push:
new 1d0243e Fix possible unsafe code warnings reported with VS 2017
1d0243e is described below
commit 1d0243e11991ca6716050094e7c456e285be1356
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Sep 30 13:03:51 2019 +0100
Fix possible unsafe code warnings reported with VS 2017
---
src/native/windows/apps/prunsrv/prunsrv.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 022ab31..5cb816a 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -321,14 +321,16 @@ static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper, LPAPXCMDLINE lpCmdline)
*/
if (!aOut)
DeleteFileW(lpWrapper->szStdOutFilename);
- if ((lpWrapper->fpStdOutFile = _wfopen(lpWrapper->szStdOutFilename,
- L"a"))) {
+ if ((_wfopen_s(&lpWrapper->fpStdOutFile,
+ lpWrapper->szStdOutFilename,
+ L"a"))) {
+ lpWrapper->szStdOutFilename = NULL;
+ }
+ else {
_dup2(_fileno(lpWrapper->fpStdOutFile), 1);
*stdout = *lpWrapper->fpStdOutFile;
setvbuf(stdout, NULL, _IONBF, 0);
}
- else
- lpWrapper->szStdOutFilename = NULL;
}
if (lpWrapper->szStdErrFilename) {
if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
@@ -345,14 +347,16 @@ static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper, LPAPXCMDLINE lpCmdline)
}
if (!aErr)
DeleteFileW(lpWrapper->szStdErrFilename);
- if ((lpWrapper->fpStdErrFile = _wfopen(lpWrapper->szStdErrFilename,
- L"a"))) {
+ if ((_wfopen_s(&lpWrapper->fpStdErrFile,
+ lpWrapper->szStdErrFilename,
+ L"a"))) {
+ lpWrapper->szStdOutFilename = NULL;
+ }
+ else {
_dup2(_fileno(lpWrapper->fpStdErrFile), 2);
*stderr = *lpWrapper->fpStdErrFile;
setvbuf(stderr, NULL, _IONBF, 0);
}
- else
- lpWrapper->szStdOutFilename = NULL;
}
else if (lpWrapper->fpStdOutFile) {
_dup2(_fileno(lpWrapper->fpStdOutFile), 2);
@@ -1338,9 +1342,9 @@ static DWORD serviceStart()
if (gPidfileHandle != INVALID_HANDLE_VALUE) {
DWORD wr = 0;
if (_jni_startup)
- _snprintf(pids, 32, "%d\r\n", GetCurrentProcessId());
+ _snprintf_s(pids, _countof(pids), 32, "%d\r\n", GetCurrentProcessId());
else
- _snprintf(pids, 32, "%d\r\n", apxProcessGetPid(gWorker));
+ _snprintf_s(pids, _countof(pids), 32, "%d\r\n", apxProcessGetPid(gWorker));
WriteFile(gPidfileHandle, pids, (DWORD)strlen(pids), &wr, NULL);
FlushFileBuffers(gPidfileName);
}