Mercurial > hg > nginx
comparison src/http/ngx_http_variables.c @ 4558:8865fd1f3aa5
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 27 Mar 2012 16:42:34 +0000 |
parents | ba39af7274ed |
children | 67653855682e |
comparison
equal
deleted
inserted
replaced
4557:b13419459a50 | 4558:8865fd1f3aa5 |
---|---|
1271 | 1271 |
1272 static ngx_int_t | 1272 static ngx_int_t |
1273 ngx_http_variable_realpath_root(ngx_http_request_t *r, | 1273 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1274 ngx_http_variable_value_t *v, uintptr_t data) | 1274 ngx_http_variable_value_t *v, uintptr_t data) |
1275 { | 1275 { |
1276 u_char *real; | |
1276 size_t len; | 1277 size_t len; |
1277 ngx_str_t path; | 1278 ngx_str_t path; |
1278 ngx_http_core_loc_conf_t *clcf; | 1279 ngx_http_core_loc_conf_t *clcf; |
1279 u_char real[NGX_MAX_PATH]; | 1280 #if (NGX_HAVE_MAX_PATH) |
1281 u_char buffer[NGX_MAX_PATH]; | |
1282 #endif | |
1280 | 1283 |
1281 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1284 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1282 | 1285 |
1283 if (clcf->root_lengths == NULL) { | 1286 if (clcf->root_lengths == NULL) { |
1284 path = clcf->root; | 1287 path = clcf->root; |
1296 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { | 1299 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { |
1297 return NGX_ERROR; | 1300 return NGX_ERROR; |
1298 } | 1301 } |
1299 } | 1302 } |
1300 | 1303 |
1301 if (ngx_realpath(path.data, real) == NULL) { | 1304 #if (NGX_HAVE_MAX_PATH) |
1305 real = buffer; | |
1306 #else | |
1307 real = NULL; | |
1308 #endif | |
1309 | |
1310 real = ngx_realpath(path.data, real); | |
1311 | |
1312 if (real == NULL) { | |
1302 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | 1313 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1303 ngx_realpath_n " \"%s\" failed", path.data); | 1314 ngx_realpath_n " \"%s\" failed", path.data); |
1304 return NGX_ERROR; | 1315 return NGX_ERROR; |
1305 } | 1316 } |
1306 | 1317 |
1307 len = ngx_strlen(real); | 1318 len = ngx_strlen(real); |
1308 | 1319 |
1309 v->data = ngx_pnalloc(r->pool, len); | 1320 v->data = ngx_pnalloc(r->pool, len); |
1310 if (v->data == NULL) { | 1321 if (v->data == NULL) { |
1322 #if !(NGX_HAVE_MAX_PATH) | |
1323 ngx_free(real); | |
1324 #endif | |
1311 return NGX_ERROR; | 1325 return NGX_ERROR; |
1312 } | 1326 } |
1313 | 1327 |
1314 v->len = len; | 1328 v->len = len; |
1315 v->valid = 1; | 1329 v->valid = 1; |
1316 v->no_cacheable = 0; | 1330 v->no_cacheable = 0; |
1317 v->not_found = 0; | 1331 v->not_found = 0; |
1318 | 1332 |
1319 ngx_memcpy(v->data, real, len); | 1333 ngx_memcpy(v->data, real, len); |
1334 | |
1335 #if !(NGX_HAVE_MAX_PATH) | |
1336 ngx_free(real); | |
1337 #endif | |
1320 | 1338 |
1321 return NGX_OK; | 1339 return NGX_OK; |
1322 } | 1340 } |
1323 | 1341 |
1324 | 1342 |