Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
4d105386
Commit
4d105386
authored
Jan 11, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better handling of non-ascii chars for windows CGIs
parent
44a35bb5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
mongoose.c
mongoose.c
+24
-13
No files found.
mongoose.c
View file @
4d105386
...
@@ -414,7 +414,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
...
@@ -414,7 +414,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
#ifdef _WIN32
#ifdef _WIN32
// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
// wbuf and wbuf_len is a target buffer and its length.
// wbuf and wbuf_len is a target buffer and its length.
static
void
to_
unicode
(
const
char
*
path
,
wchar_t
*
wbuf
,
size_t
wbuf_len
)
{
static
void
to_
wchar
(
const
char
*
path
,
wchar_t
*
wbuf
,
size_t
wbuf_len
)
{
char
buf
[
MAX_PATH_SIZE
*
2
],
buf2
[
MAX_PATH_SIZE
*
2
],
*
p
;
char
buf
[
MAX_PATH_SIZE
*
2
],
buf2
[
MAX_PATH_SIZE
*
2
],
*
p
;
strncpy
(
buf
,
path
,
sizeof
(
buf
));
strncpy
(
buf
,
path
,
sizeof
(
buf
));
...
@@ -438,21 +438,21 @@ static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len) {
...
@@ -438,21 +438,21 @@ static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len) {
static
int
mg_stat
(
const
char
*
path
,
file_stat_t
*
st
)
{
static
int
mg_stat
(
const
char
*
path
,
file_stat_t
*
st
)
{
wchar_t
wpath
[
MAX_PATH_SIZE
];
wchar_t
wpath
[
MAX_PATH_SIZE
];
to_
unicode
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
to_
wchar
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
DBG
((
"[%ls] -> %d"
,
wpath
,
_wstati64
(
wpath
,
st
)));
DBG
((
"[%ls] -> %d"
,
wpath
,
_wstati64
(
wpath
,
st
)));
return
_wstati64
(
wpath
,
st
);
return
_wstati64
(
wpath
,
st
);
}
}
static
FILE
*
mg_fopen
(
const
char
*
path
,
const
char
*
mode
)
{
static
FILE
*
mg_fopen
(
const
char
*
path
,
const
char
*
mode
)
{
wchar_t
wpath
[
MAX_PATH_SIZE
],
wmode
[
10
];
wchar_t
wpath
[
MAX_PATH_SIZE
],
wmode
[
10
];
to_
unicode
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
to_
wchar
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
to_
unicode
(
mode
,
wmode
,
ARRAY_SIZE
(
wmode
));
to_
wchar
(
mode
,
wmode
,
ARRAY_SIZE
(
wmode
));
return
_wfopen
(
wpath
,
wmode
);
return
_wfopen
(
wpath
,
wmode
);
}
}
static
int
mg_open
(
const
char
*
path
,
int
flag
)
{
static
int
mg_open
(
const
char
*
path
,
int
flag
)
{
wchar_t
wpath
[
MAX_PATH_SIZE
];
wchar_t
wpath
[
MAX_PATH_SIZE
];
to_
unicode
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
to_
wchar
(
path
,
wpath
,
ARRAY_SIZE
(
wpath
));
return
_wopen
(
wpath
,
flag
);
return
_wopen
(
wpath
,
flag
);
}
}
#endif
#endif
...
@@ -851,12 +851,21 @@ static void spawn_stdio_thread(int sock, HANDLE hPipe, void *(*func)(void *)) {
...
@@ -851,12 +851,21 @@ static void spawn_stdio_thread(int sock, HANDLE hPipe, void *(*func)(void *)) {
}
}
}
}
static
void
abs_path
(
const
char
*
utf8_path
,
char
*
abs_path
,
size_t
len
)
{
wchar_t
buf
[
MAX_PATH_SIZE
],
buf2
[
MAX_PATH_SIZE
];
to_wchar
(
utf8_path
,
buf
,
ARRAY_SIZE
(
buf
));
GetFullPathNameW
(
buf
,
ARRAY_SIZE
(
buf2
),
buf2
,
NULL
);
WideCharToMultiByte
(
CP_UTF8
,
0
,
buf2
,
wcslen
(
buf2
)
+
1
,
abs_path
,
len
,
0
,
0
);
}
static
pid_t
start_process
(
char
*
interp
,
const
char
*
cmd
,
const
char
*
env
,
static
pid_t
start_process
(
char
*
interp
,
const
char
*
cmd
,
const
char
*
env
,
const
char
*
envp
[],
const
char
*
dir
,
sock_t
sock
)
{
const
char
*
envp
[],
const
char
*
dir
,
sock_t
sock
)
{
STARTUPINFO
A
si
=
{
0
};
STARTUPINFO
W
si
=
{
0
};
PROCESS_INFORMATION
pi
=
{
0
};
PROCESS_INFORMATION
pi
=
{
0
};
HANDLE
a
[
2
],
b
[
2
],
me
=
GetCurrentProcess
();
HANDLE
a
[
2
],
b
[
2
],
me
=
GetCurrentProcess
();
char
cmdline
[
MAX_PATH_SIZE
],
full_dir
[
MAX_PATH_SIZE
],
buf
[
MAX_PATH_SIZE
],
*
p
;
wchar_t
wcmd
[
MAX_PATH_SIZE
],
full_dir
[
MAX_PATH_SIZE
];
char
buf
[
MAX_PATH_SIZE
],
buf4
[
MAX_PATH_SIZE
],
buf5
[
MAX_PATH_SIZE
],
cmdline
[
MAX_PATH_SIZE
],
*
p
;
DWORD
flags
=
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
;
DWORD
flags
=
DUPLICATE_CLOSE_SOURCE
|
DUPLICATE_SAME_ACCESS
;
FILE
*
fp
;
FILE
*
fp
;
...
@@ -883,14 +892,16 @@ static pid_t start_process(char *interp, const char *cmd, const char *env,
...
@@ -883,14 +892,16 @@ static pid_t start_process(char *interp, const char *cmd, const char *env,
}
}
if
(
interp
!=
NULL
)
{
if
(
interp
!=
NULL
)
{
GetFullPathName
(
interp
,
sizeof
(
buf
),
buf
,
NULL
);
abs_path
(
interp
,
buf4
,
ARRAY_SIZE
(
buf4
)
);
interp
=
buf
;
interp
=
buf
;
}
}
GetFullPathName
(
dir
,
sizeof
(
full_dir
),
full_dir
,
NULL
);
abs_path
(
dir
,
buf5
,
ARRAY_SIZE
(
buf5
));
to_wchar
(
dir
,
full_dir
,
ARRAY_SIZE
(
full_dir
));
mg_snprintf
(
cmdline
,
sizeof
(
cmdline
),
"%s%s
\"
%s
\"
"
,
mg_snprintf
(
cmdline
,
sizeof
(
cmdline
),
"%s%s
\"
%s
\"
"
,
interp
?
interp
:
""
,
interp
?
" "
:
""
,
cmd
);
interp
?
interp
:
""
,
interp
?
" "
:
""
,
cmd
);
to_wchar
(
cmdline
,
wcmd
,
ARRAY_SIZE
(
wcmd
));
if
(
CreateProcess
(
NULL
,
cmdline
,
NULL
,
NULL
,
TRUE
,
CREATE_NEW_PROCESS_GROUP
,
if
(
CreateProcess
W
(
NULL
,
wcmd
,
NULL
,
NULL
,
TRUE
,
CREATE_NEW_PROCESS_GROUP
,
(
void
*
)
env
,
full_dir
,
&
si
,
&
pi
)
!=
0
)
{
(
void
*
)
env
,
full_dir
,
&
si
,
&
pi
)
!=
0
)
{
spawn_stdio_thread
(
sock
,
a
[
1
],
push_to_stdin
);
spawn_stdio_thread
(
sock
,
a
[
1
],
push_to_stdin
);
spawn_stdio_thread
(
sock
,
b
[
0
],
pull_from_stdout
);
spawn_stdio_thread
(
sock
,
b
[
0
],
pull_from_stdout
);
...
@@ -899,7 +910,7 @@ static pid_t start_process(char *interp, const char *cmd, const char *env,
...
@@ -899,7 +910,7 @@ static pid_t start_process(char *interp, const char *cmd, const char *env,
CloseHandle
(
b
[
0
]);
CloseHandle
(
b
[
0
]);
closesocket
(
sock
);
closesocket
(
sock
);
}
}
DBG
((
"CGI command: [%
s] -> %p"
,
cmdline
,
pi
.
hProcess
));
DBG
((
"CGI command: [%
ls] -> %p"
,
wcmd
,
pi
.
hProcess
));
CloseHandle
(
si
.
hStdOutput
);
CloseHandle
(
si
.
hStdOutput
);
CloseHandle
(
si
.
hStdInput
);
CloseHandle
(
si
.
hStdInput
);
...
@@ -2187,7 +2198,7 @@ static DIR *opendir(const char *name) {
...
@@ -2187,7 +2198,7 @@ static DIR *opendir(const char *name) {
}
else
if
((
dir
=
(
DIR
*
)
malloc
(
sizeof
(
*
dir
)))
==
NULL
)
{
}
else
if
((
dir
=
(
DIR
*
)
malloc
(
sizeof
(
*
dir
)))
==
NULL
)
{
SetLastError
(
ERROR_NOT_ENOUGH_MEMORY
);
SetLastError
(
ERROR_NOT_ENOUGH_MEMORY
);
}
else
{
}
else
{
to_
unicode
(
name
,
wpath
,
ARRAY_SIZE
(
wpath
));
to_
wchar
(
name
,
wpath
,
ARRAY_SIZE
(
wpath
));
attrs
=
GetFileAttributesW
(
wpath
);
attrs
=
GetFileAttributesW
(
wpath
);
if
(
attrs
!=
0xFFFFFFFF
&&
if
(
attrs
!=
0xFFFFFFFF
&&
((
attrs
&
FILE_ATTRIBUTE_DIRECTORY
)
==
FILE_ATTRIBUTE_DIRECTORY
))
{
((
attrs
&
FILE_ATTRIBUTE_DIRECTORY
)
==
FILE_ATTRIBUTE_DIRECTORY
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment