Skip to content

Commit 247f41f

Browse files
authored
Merge pull request #27 from libxengine/autofix/high/alert-47
[Autofix][high] Alert #47: File created without restricting permissions
2 parents 47ed80a + 0ab3fd3 commit 247f41f

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

XEngine_Module/XEngine_AIApi/pch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
// 添加要在此处预编译的标头
1111
#define _CRT_SECURE_NO_WARNINGS
1212
#include "framework.h"
13+
#include <io.h>
1314
#endif
1415
#endif //PCH_H
1516
#include <stdio.h>
1617
#include <stdlib.h>
1718
#include <string.h>
18-
#include <io.h>
1919
#include <fcntl.h>
20+
#include <sys/stat.h>
21+
#include <sys/types.h>
2022
#include <json/json.h>
2123
#include <thread>
2224
#include <memory>

XEngine_Module/XEngine_Verification/Verification_XAuth/Verification_XAuthKey.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,17 @@ bool CVerification_XAuthKey::Verification_XAuthKey_FileWrite(VERIFICATION_XAUTHK
151151
{
152152
return false;
153153
}
154-
//打开文件
155-
FILE* pSt_File = _xtfopen(lpszKeyFile, _X("wb"));
154+
//打开文件(限制为仅当前用户可读写)
155+
#ifdef _MSC_BUILD
156+
int nFile = _xtopen(lpszKeyFile, _O_WRONLY | _O_CREAT | _O_TRUNC | _O_BINARY, _S_IREAD | _S_IWRITE);
157+
FILE* pSt_File = _fdopen(nFile, "wb");
158+
#else
159+
int nFile = _xtopen(lpszKeyFile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
160+
FILE* pSt_File = fdopen(nFile, "wb");
161+
#endif
156162
if (NULL == pSt_File)
157163
{
164+
_close(nFile);
158165
Verification_IsErrorOccur = true;
159166
Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_OPENFILE;
160167
return false;

XEngine_Module/XEngine_Verification/pch.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88
#define PCH_H
99
#ifdef _MSC_BUILD
1010
#define _CRT_SECURE_NO_WARNINGS
11-
#include <io.h>
1211
// 添加要在此处预编译的标头
1312
#include "framework.h"
13+
#include <io.h>
1414
#else
1515
#include <unistd.h>
16-
#include <fcntl.h>
1716
#endif
1817
#endif //PCH_H
1918
#include <stdio.h>
2019
#include <stdlib.h>
2120
#include <string.h>
2221
#include <errno.h>
2322
#include <fcntl.h>
23+
#include <sys/stat.h>
24+
#include <sys/types.h>
2425
#include <json/json.h>
2526
#include <shared_mutex>
2627
#include <thread>

0 commit comments

Comments
 (0)