|
@@ -532,19 +532,18 @@ typedef const char *SOCK_OPT_TYPE;
|
|
|
/* For a detailed description of these defines, see
|
|
|
* https://github.com/civetweb/civetweb/issues/937 (Nov 15, 2020). */
|
|
|
|
|
|
-/* The Microsoft SDK does not define PATH_MAX, but mingw does. */
|
|
|
-#ifdef PATH_MAX
|
|
|
-#undef PATH_MAX
|
|
|
-#endif
|
|
|
-/* PATH_MAX is a char buffer size for 259 BMP characters in UTF-8 plus
|
|
|
+/* UTF8_PATH_MAX is a char buffer size for 259 BMP characters in UTF-8 plus
|
|
|
* null termination, rounded up to the next 4 bytes boundary */
|
|
|
-#define PATH_MAX (3 * 260)
|
|
|
-/* W_PATH_MAX is the wchar_t buffer size required for 259 BMP characters
|
|
|
- * plus termination. (Note: wchar_t is 16 bit on Windows) */
|
|
|
-#define W_PATH_MAX (260)
|
|
|
+#define UTF8_PATH_MAX (3 * 260)
|
|
|
+/* UTF16_PATH_MAX is the 16-bit wchar_t buffer size required for 259 BMP
|
|
|
+ * characters plus termination. (Note: wchar_t is 16 bit on Windows) */
|
|
|
+#define UTF16_PATH_MAX (260)
|
|
|
+#else
|
|
|
+/* Linux & co. already use UTF-8 */
|
|
|
+#define UTF8_PATH_MAX (PATH_MAX)
|
|
|
#endif
|
|
|
|
|
|
-mg_static_assert(PATH_MAX >= 12, "path length must be a positive number");
|
|
|
+mg_static_assert(UTF8_PATH_MAX >= 12, "path length must be a positive number");
|
|
|
|
|
|
|
|
|
#if !defined(_IN_PORT_T)
|
|
@@ -826,7 +825,7 @@ static const char *mg_fgets(char *buf, size_t size, struct mg_file *filep);
|
|
|
|
|
|
/* POSIX dirent interface */
|
|
|
struct dirent {
|
|
|
- char d_name[PATH_MAX];
|
|
|
+ char d_name[UTF8_PATH_MAX];
|
|
|
};
|
|
|
|
|
|
typedef struct DIR {
|
|
@@ -1181,8 +1180,8 @@ FUNCTION_MAY_BE_UNUSED
|
|
|
static int
|
|
|
rename(const char *a, const char *b)
|
|
|
{
|
|
|
- wchar_t wa[W_PATH_MAX];
|
|
|
- wchar_t wb[W_PATH_MAX];
|
|
|
+ wchar_t wa[UTF16_PATH_MAX];
|
|
|
+ wchar_t wb[UTF16_PATH_MAX];
|
|
|
path_to_unicode(NULL, a, wa, ARRAY_SIZE(wa));
|
|
|
path_to_unicode(NULL, b, wb, ARRAY_SIZE(wb));
|
|
|
|
|
@@ -1200,7 +1199,7 @@ FUNCTION_MAY_BE_UNUSED
|
|
|
static int
|
|
|
stat(const char *name, struct stat *st)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attr;
|
|
|
time_t creation_time, write_time;
|
|
|
|
|
@@ -3528,7 +3527,7 @@ mg_fopen(const struct mg_connection *conn,
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf));
|
|
|
switch (mode) {
|
|
|
case MG_FOPEN_MODE_READ:
|
|
@@ -4985,7 +4984,7 @@ mg_send_http_error_impl(struct mg_connection *conn,
|
|
|
int has_body;
|
|
|
|
|
|
#if !defined(NO_FILESYSTEMS)
|
|
|
- char path_buf[PATH_MAX];
|
|
|
+ char path_buf[UTF8_PATH_MAX];
|
|
|
int len, i, page_handler_found, scope, truncated;
|
|
|
const char *error_handler = NULL;
|
|
|
struct mg_file error_page_file = STRUCT_FILE_INITIALIZER;
|
|
@@ -5581,8 +5580,8 @@ path_to_unicode(const struct mg_connection *conn,
|
|
|
wchar_t *wbuf,
|
|
|
size_t wbuf_len)
|
|
|
{
|
|
|
- char buf[PATH_MAX], buf2[PATH_MAX];
|
|
|
- wchar_t wbuf2[W_PATH_MAX + 1];
|
|
|
+ char buf[UTF8_PATH_MAX], buf2[UTF8_PATH_MAX];
|
|
|
+ wchar_t wbuf2[UTF16_PATH_MAX + 1];
|
|
|
DWORD long_len, err;
|
|
|
int (*fcompare)(const wchar_t *, const wchar_t *) = mg_wcscasecmp;
|
|
|
|
|
@@ -5652,7 +5651,7 @@ mg_stat(const struct mg_connection *conn,
|
|
|
const char *path,
|
|
|
struct mg_file_stat *filep)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
WIN32_FILE_ATTRIBUTE_DATA info;
|
|
|
time_t creation_time;
|
|
|
size_t len;
|
|
@@ -5700,7 +5699,7 @@ mg_stat(const struct mg_connection *conn,
|
|
|
static int
|
|
|
mg_remove(const struct mg_connection *conn, const char *path)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf));
|
|
|
return DeleteFileW(wbuf) ? 0 : -1;
|
|
|
}
|
|
@@ -5709,7 +5708,7 @@ mg_remove(const struct mg_connection *conn, const char *path)
|
|
|
static int
|
|
|
mg_mkdir(const struct mg_connection *conn, const char *path, int mode)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
(void)mode;
|
|
|
path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf));
|
|
|
return CreateDirectoryW(wbuf, NULL) ? 0 : -1;
|
|
@@ -5731,7 +5730,7 @@ static DIR *
|
|
|
mg_opendir(const struct mg_connection *conn, const char *name)
|
|
|
{
|
|
|
DIR *dir = NULL;
|
|
|
- wchar_t wpath[W_PATH_MAX];
|
|
|
+ wchar_t wpath[UTF16_PATH_MAX];
|
|
|
DWORD attrs;
|
|
|
|
|
|
if (name == NULL) {
|
|
@@ -5970,7 +5969,7 @@ FUNCTION_MAY_BE_UNUSED
|
|
|
static HANDLE
|
|
|
dlopen(const char *dll_name, int flags)
|
|
|
{
|
|
|
- wchar_t wbuf[W_PATH_MAX];
|
|
|
+ wchar_t wbuf[UTF16_PATH_MAX];
|
|
|
(void)flags;
|
|
|
path_to_unicode(NULL, dll_name, wbuf, ARRAY_SIZE(wbuf));
|
|
|
return LoadLibraryW(wbuf);
|
|
@@ -6065,7 +6064,7 @@ spawn_process(struct mg_connection *conn,
|
|
|
HANDLE me;
|
|
|
char *interp;
|
|
|
char *interp_arg = 0;
|
|
|
- char full_dir[PATH_MAX], cmdline[PATH_MAX], buf[PATH_MAX];
|
|
|
+ char full_dir[UTF8_PATH_MAX], cmdline[UTF8_PATH_MAX], buf[UTF8_PATH_MAX];
|
|
|
int truncated;
|
|
|
struct mg_file file = STRUCT_FILE_INITIALIZER;
|
|
|
STARTUPINFOA si;
|
|
@@ -7955,7 +7954,7 @@ interpret_uri(struct mg_connection *conn, /* in/out: request (must be valid) */
|
|
|
const char *rewrite;
|
|
|
struct vec a, b;
|
|
|
ptrdiff_t match_len;
|
|
|
- char gz_path[PATH_MAX];
|
|
|
+ char gz_path[UTF8_PATH_MAX];
|
|
|
int truncated;
|
|
|
#if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
|
|
|
char *tmp_str;
|
|
@@ -8138,7 +8137,8 @@ interpret_uri(struct mg_connection *conn, /* in/out: request (must be valid) */
|
|
|
/* Step 10: Script resources may handle sub-resources */
|
|
|
/* Support PATH_INFO for CGI scripts. */
|
|
|
tmp_str_len = strlen(filename);
|
|
|
- tmp_str = (char *)mg_malloc_ctx(tmp_str_len + PATH_MAX + 1, conn->phys_ctx);
|
|
|
+ tmp_str =
|
|
|
+ (char *)mg_malloc_ctx(tmp_str_len + UTF8_PATH_MAX + 1, conn->phys_ctx);
|
|
|
if (!tmp_str) {
|
|
|
/* Out of memory */
|
|
|
goto interpret_cleanup;
|
|
@@ -8176,7 +8176,7 @@ interpret_uri(struct mg_connection *conn, /* in/out: request (must be valid) */
|
|
|
|
|
|
if (allow_substitute_script_subresources) {
|
|
|
if (substitute_index_file(
|
|
|
- conn, tmp_str, tmp_str_len + PATH_MAX, filestat)) {
|
|
|
+ conn, tmp_str, tmp_str_len + UTF8_PATH_MAX, filestat)) {
|
|
|
|
|
|
/* some intermediate directory has an index file */
|
|
|
if (extention_matches_script(conn, tmp_str)) {
|
|
@@ -8770,7 +8770,7 @@ open_auth_file(struct mg_connection *conn,
|
|
|
struct mg_file *filep)
|
|
|
{
|
|
|
if ((conn != NULL) && (conn->dom_ctx != NULL)) {
|
|
|
- char name[PATH_MAX];
|
|
|
+ char name[UTF8_PATH_MAX];
|
|
|
const char *p, *e,
|
|
|
*gpass = conn->dom_ctx->config[GLOBAL_PASSWORDS_FILE];
|
|
|
int truncated;
|
|
@@ -9161,7 +9161,7 @@ static int
|
|
|
check_authorization(struct mg_connection *conn, const char *path)
|
|
|
{
|
|
|
#if !defined(NO_FILESYSTEMS)
|
|
|
- char fname[PATH_MAX];
|
|
|
+ char fname[UTF8_PATH_MAX];
|
|
|
struct vec uri_vec, filename_vec;
|
|
|
const char *list;
|
|
|
struct mg_file file = STRUCT_FILE_INITIALIZER;
|
|
@@ -9302,7 +9302,7 @@ mg_modify_passwords_file(const char *fname,
|
|
|
const char *pass)
|
|
|
{
|
|
|
int found, i;
|
|
|
- char line[512], u[512] = "", d[512] = "", ha1[33], tmp[PATH_MAX + 8];
|
|
|
+ char line[512], u[512] = "", d[512] = "", ha1[33], tmp[UTF8_PATH_MAX + 8];
|
|
|
FILE *fp, *fp2;
|
|
|
|
|
|
found = 0;
|
|
@@ -9348,7 +9348,7 @@ mg_modify_passwords_file(const char *fname,
|
|
|
}
|
|
|
|
|
|
/* The maximum length of the path to the password file is limited */
|
|
|
- if ((strlen(fname) + 4) >= PATH_MAX) {
|
|
|
+ if ((strlen(fname) + 4) >= UTF8_PATH_MAX) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -9888,7 +9888,7 @@ scan_directory(struct mg_connection *conn,
|
|
|
void *data,
|
|
|
int (*cb)(struct de *, void *))
|
|
|
{
|
|
|
- char path[PATH_MAX];
|
|
|
+ char path[UTF8_PATH_MAX];
|
|
|
struct dirent *dp;
|
|
|
DIR *dirp;
|
|
|
struct de de;
|
|
@@ -9945,7 +9945,7 @@ scan_directory(struct mg_connection *conn,
|
|
|
static int
|
|
|
remove_directory(struct mg_connection *conn, const char *dir)
|
|
|
{
|
|
|
- char path[PATH_MAX];
|
|
|
+ char path[UTF8_PATH_MAX];
|
|
|
struct dirent *dp;
|
|
|
DIR *dirp;
|
|
|
struct de de;
|
|
@@ -10324,7 +10324,7 @@ handle_static_file_request(struct mg_connection *conn,
|
|
|
int64_t cl, r1, r2;
|
|
|
struct vec mime_vec;
|
|
|
int n, truncated;
|
|
|
- char gz_path[PATH_MAX];
|
|
|
+ char gz_path[UTF8_PATH_MAX];
|
|
|
const char *encoding = 0;
|
|
|
const char *origin_hdr;
|
|
|
const char *cors_orig_cfg;
|
|
@@ -10686,7 +10686,7 @@ mg_send_mime_file2(struct mg_connection *conn,
|
|
|
static int
|
|
|
put_dir(struct mg_connection *conn, const char *path)
|
|
|
{
|
|
|
- char buf[PATH_MAX];
|
|
|
+ char buf[UTF8_PATH_MAX];
|
|
|
const char *s, *p;
|
|
|
struct mg_file file = STRUCT_FILE_INITIALIZER;
|
|
|
size_t len;
|
|
@@ -11697,7 +11697,7 @@ handle_cgi_request(struct mg_connection *conn, const char *prog)
|
|
|
int headers_len, data_len, i, truncated;
|
|
|
int fdin[2] = {-1, -1}, fdout[2] = {-1, -1}, fderr[2] = {-1, -1};
|
|
|
const char *status, *status_text, *connection_state;
|
|
|
- char *pbuf, dir[PATH_MAX], *p;
|
|
|
+ char *pbuf, dir[UTF8_PATH_MAX], *p;
|
|
|
struct mg_request_info ri;
|
|
|
struct cgi_environment blk;
|
|
|
FILE *in = NULL, *out = NULL, *err = NULL;
|
|
@@ -14383,7 +14383,7 @@ static void
|
|
|
handle_request(struct mg_connection *conn)
|
|
|
{
|
|
|
struct mg_request_info *ri = &conn->request_info;
|
|
|
- char path[PATH_MAX];
|
|
|
+ char path[UTF8_PATH_MAX];
|
|
|
int uri_len, ssl_index;
|
|
|
int is_found = 0, is_script_resource = 0, is_websocket_request = 0,
|
|
|
is_put_or_delete_request = 0, is_callback_resource = 0,
|