mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
Fixed unconditional MAX_PATH usage (ticket #22).
POSIX doesn't require it to be defined, and Debian GNU/Hurd doesn't define it. Note that if there is no MAX_PATH defined we have to use realpath() with NULL argument and free() the result.
This commit is contained in:
parent
7b2b17a6b3
commit
36aef0c383
@ -1273,10 +1273,13 @@ static ngx_int_t
|
|||||||
ngx_http_variable_realpath_root(ngx_http_request_t *r,
|
ngx_http_variable_realpath_root(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data)
|
ngx_http_variable_value_t *v, uintptr_t data)
|
||||||
{
|
{
|
||||||
|
u_char *real;
|
||||||
size_t len;
|
size_t len;
|
||||||
ngx_str_t path;
|
ngx_str_t path;
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
u_char real[NGX_MAX_PATH];
|
#if (NGX_HAVE_MAX_PATH)
|
||||||
|
u_char buffer[NGX_MAX_PATH];
|
||||||
|
#endif
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
@ -1298,7 +1301,15 @@ ngx_http_variable_realpath_root(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_realpath(path.data, real) == NULL) {
|
#if (NGX_HAVE_MAX_PATH)
|
||||||
|
real = buffer;
|
||||||
|
#else
|
||||||
|
real = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
real = ngx_realpath(path.data, real);
|
||||||
|
|
||||||
|
if (real == NULL) {
|
||||||
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
||||||
ngx_realpath_n " \"%s\" failed", path.data);
|
ngx_realpath_n " \"%s\" failed", path.data);
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
@ -1308,6 +1319,9 @@ ngx_http_variable_realpath_root(ngx_http_request_t *r,
|
|||||||
|
|
||||||
v->data = ngx_pnalloc(r->pool, len);
|
v->data = ngx_pnalloc(r->pool, len);
|
||||||
if (v->data == NULL) {
|
if (v->data == NULL) {
|
||||||
|
#if !(NGX_HAVE_MAX_PATH)
|
||||||
|
ngx_free(real);
|
||||||
|
#endif
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1318,6 +1332,10 @@ ngx_http_variable_realpath_root(ngx_http_request_t *r,
|
|||||||
|
|
||||||
ngx_memcpy(v->data, real, len);
|
ngx_memcpy(v->data, real, len);
|
||||||
|
|
||||||
|
#if !(NGX_HAVE_MAX_PATH)
|
||||||
|
ngx_free(real);
|
||||||
|
#endif
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,14 +200,25 @@ void ngx_close_file_mapping(ngx_file_mapping_t *fm);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define ngx_realpath(p, r) realpath((char *) p, (char *) r)
|
#define ngx_realpath(p, r) (u_char *) realpath((char *) p, (char *) r)
|
||||||
#define ngx_realpath_n "realpath()"
|
#define ngx_realpath_n "realpath()"
|
||||||
#define ngx_getcwd(buf, size) (getcwd((char *) buf, size) != NULL)
|
#define ngx_getcwd(buf, size) (getcwd((char *) buf, size) != NULL)
|
||||||
#define ngx_getcwd_n "getcwd()"
|
#define ngx_getcwd_n "getcwd()"
|
||||||
#define ngx_path_separator(c) ((c) == '/')
|
#define ngx_path_separator(c) ((c) == '/')
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(PATH_MAX)
|
||||||
|
|
||||||
|
#define NGX_HAVE_MAX_PATH 1
|
||||||
#define NGX_MAX_PATH PATH_MAX
|
#define NGX_MAX_PATH PATH_MAX
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define NGX_MAX_PATH 4096
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define NGX_DIR_MASK_LEN 0
|
#define NGX_DIR_MASK_LEN 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,6 +183,7 @@ char *ngx_realpath(u_char *path, u_char *resolved);
|
|||||||
#define ngx_getcwd_n "GetCurrentDirectory()"
|
#define ngx_getcwd_n "GetCurrentDirectory()"
|
||||||
#define ngx_path_separator(c) ((c) == '/' || (c) == '\\')
|
#define ngx_path_separator(c) ((c) == '/' || (c) == '\\')
|
||||||
|
|
||||||
|
#define NGX_HAVE_MAX_PATH 1
|
||||||
#define NGX_MAX_PATH MAX_PATH
|
#define NGX_MAX_PATH MAX_PATH
|
||||||
|
|
||||||
#define NGX_DIR_MASK (u_char *) "/*"
|
#define NGX_DIR_MASK (u_char *) "/*"
|
||||||
|
Loading…
Reference in New Issue
Block a user