mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
mkstemp is not available in Windows build, replaced with _mktemp_s plus _open.
- Updated included headers to support compilation on Windows (using Visual C++) - Minor change to use C++ default (zero) initialization instead of calling memset.
This commit is contained in:
parent
35949179a4
commit
373633ffe2
@ -21,7 +21,12 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#ifndef WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <io.h>
|
||||||
|
#include "src/compat/msvc.h"
|
||||||
|
#endif
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -61,12 +66,11 @@ MultipartPartTmpFile::~MultipartPartTmpFile() {
|
|||||||
|
|
||||||
void MultipartPartTmpFile::Open() {
|
void MultipartPartTmpFile::Open() {
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
char tstr[300];
|
|
||||||
time_t tt = time(NULL);
|
time_t tt = time(NULL);
|
||||||
|
|
||||||
localtime_r(&tt, &timeinfo);
|
localtime_r(&tt, &timeinfo);
|
||||||
|
|
||||||
memset(tstr, '\0', 300);
|
char tstr[300] {};
|
||||||
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
|
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
|
||||||
|
|
||||||
std::string path = m_transaction->m_rules->m_uploadDirectory.m_value;
|
std::string path = m_transaction->m_rules->m_uploadDirectory.m_value;
|
||||||
@ -74,14 +78,23 @@ void MultipartPartTmpFile::Open() {
|
|||||||
path += "-file-XXXXXX";
|
path += "-file-XXXXXX";
|
||||||
|
|
||||||
char* tmp = strdup(path.c_str());
|
char* tmp = strdup(path.c_str());
|
||||||
|
#ifndef WIN32
|
||||||
m_tmp_file_fd = mkstemp(tmp);
|
m_tmp_file_fd = mkstemp(tmp);
|
||||||
|
#else
|
||||||
|
_mktemp_s(tmp, path.length()+1);
|
||||||
|
m_tmp_file_fd = _open(tmp, _O_CREAT | _O_EXCL | _O_RDWR);
|
||||||
|
#endif
|
||||||
m_tmp_file_name.assign(tmp);
|
m_tmp_file_name.assign(tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name);
|
ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name);
|
||||||
|
|
||||||
int mode = m_transaction->m_rules->m_uploadFileMode.m_value;
|
int mode = m_transaction->m_rules->m_uploadFileMode.m_value;
|
||||||
if ((m_tmp_file_fd != -1) && (mode != 0)) {
|
if ((m_tmp_file_fd != -1) && (mode != 0)) {
|
||||||
|
#ifndef WIN32
|
||||||
if (fchmod(m_tmp_file_fd, mode) == -1) {
|
if (fchmod(m_tmp_file_fd, mode) == -1) {
|
||||||
|
#else
|
||||||
|
if (_chmod(m_tmp_file_name.c_str(), mode) == -1) {
|
||||||
|
#endif
|
||||||
m_tmp_file_fd = -1;
|
m_tmp_file_fd = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user