Skip to content

Commit 638cad4

Browse files
committed
Fixed handling trailing slashes.
1 parent 4f3a133 commit 638cad4

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

ngx_http_dav_ext_module.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,17 @@ ngx_http_dav_ext_lock_lookup(ngx_http_request_t *r,
372372
ngx_http_dav_ext_lock_t *lock, ngx_str_t *uri, ngx_int_t depth)
373373
{
374374
time_t now;
375+
u_char *p;
375376
ngx_queue_t *q;
376377
ngx_http_dav_ext_node_t *node;
377378

378379
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
379380
"http dav_ext lock lookup \"%V\"", uri);
380381

382+
if (uri->len == 0) {
383+
return NULL;
384+
}
385+
381386
now = ngx_time();
382387

383388
while (!ngx_queue_empty(&lock->sh->queue)) {
@@ -404,15 +409,16 @@ ngx_http_dav_ext_lock_lookup(ngx_http_request_t *r,
404409
}
405410

406411
if (uri->len > node->len) {
407-
if (uri->data[node->len] != '/') {
412+
if (node->data[node->len - 1] != '/') {
408413
continue;
409414
}
410415

411-
if (!node->infinite
412-
&& ngx_strlchr(uri->data + node->len + 1,
413-
uri->data + uri->len, '/'))
414-
{
415-
continue;
416+
if (!node->infinite) {
417+
p = ngx_strlchr(uri->data + node->len, uri->data + uri->len,
418+
'/');
419+
if (p && p != uri->data + uri->len - 1) {
420+
continue;
421+
}
416422
}
417423
}
418424

@@ -430,15 +436,16 @@ ngx_http_dav_ext_lock_lookup(ngx_http_request_t *r,
430436
continue;
431437
}
432438

433-
if (node->data[uri->len] != '/') {
439+
if (uri->data[uri->len - 1] != '/') {
434440
continue;
435441
}
436442

437-
if (depth == 0
438-
&& ngx_strlchr(node->data + uri->len + 1,
439-
node->data + node->len, '/'))
440-
{
441-
continue;
443+
if (depth == 0) {
444+
p = ngx_strlchr(node->data + uri->len, node->data + node->len,
445+
'/');
446+
if (p && p != node->data + node->len - 1) {
447+
continue;
448+
}
442449
}
443450

444451
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -1113,13 +1120,17 @@ ngx_http_dav_ext_lock_handler(ngx_http_request_t *r)
11131120
uint32_t token;
11141121
ngx_fd_t fd;
11151122
ngx_int_t rc, depth;
1116-
ngx_str_t path, uri;
1123+
ngx_str_t path;
11171124
ngx_uint_t status;
11181125
ngx_file_info_t fi;
11191126
ngx_http_dav_ext_lock_t *lock;
11201127
ngx_http_dav_ext_node_t *node;
11211128
ngx_http_dav_ext_loc_conf_t *dlcf;
11221129

1130+
if (r->uri.len == 0) {
1131+
return NGX_HTTP_BAD_REQUEST;
1132+
}
1133+
11231134
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_ext_module);
11241135

11251136
lock = dlcf->shm_zone->data;
@@ -1151,13 +1162,11 @@ ngx_http_dav_ext_lock_handler(ngx_http_request_t *r)
11511162
token = ngx_random();
11521163
}
11531164

1154-
uri = r->uri;
1155-
11561165
now = ngx_time();
11571166

11581167
ngx_shmtx_lock(&lock->shpool->mutex);
11591168

1160-
node = ngx_http_dav_ext_lock_lookup(r, lock, &uri, depth);
1169+
node = ngx_http_dav_ext_lock_lookup(r, lock, &r->uri, depth);
11611170

11621171
if (node) {
11631172
if (node->token != token) {
@@ -1179,10 +1188,7 @@ ngx_http_dav_ext_lock_handler(ngx_http_request_t *r)
11791188
depth, token);
11801189
}
11811190

1182-
n = sizeof(ngx_http_dav_ext_node_t);
1183-
if (uri.len) {
1184-
n += uri.len - 1;
1185-
}
1191+
n = sizeof(ngx_http_dav_ext_node_t) + r->uri.len - 1;
11861192

11871193
node = ngx_slab_alloc_locked(lock->shpool, n);
11881194
if (node == NULL) {
@@ -1192,9 +1198,9 @@ ngx_http_dav_ext_lock_handler(ngx_http_request_t *r)
11921198

11931199
ngx_memzero(node, sizeof(ngx_http_dav_ext_node_t));
11941200

1195-
ngx_memcpy(&node->data, uri.data, uri.len);
1201+
ngx_memcpy(&node->data, r->uri.data, r->uri.len);
11961202

1197-
node->len = uri.len;
1203+
node->len = r->uri.len;
11981204
node->token = token;
11991205
node->expire = now + lock->timeout;
12001206
node->infinite = (depth ? 1 : 0);
@@ -1360,7 +1366,7 @@ ngx_http_dav_ext_unlock_handler(ngx_http_request_t *r)
13601366

13611367
node = ngx_http_dav_ext_lock_lookup(r, lock, &r->uri, -1);
13621368

1363-
if (node == NULL || node->len != r->uri.len || node->token != token) {
1369+
if (node == NULL || node->token != token) {
13641370
ngx_shmtx_unlock(&lock->shpool->mutex);
13651371
return NGX_HTTP_NO_CONTENT;
13661372
}
@@ -1839,7 +1845,7 @@ ngx_http_dav_ext_format_lockdiscovery(ngx_http_request_t *r, u_char *dst,
18391845
time_t now;
18401846

18411847
if (dst == NULL) {
1842-
if (entry->lock_root.len == 0) {
1848+
if (entry->lock_token == 0) {
18431849
return sizeof("<D:lockdiscovery/>\n") - 1;
18441850
}
18451851

@@ -1867,7 +1873,7 @@ ngx_http_dav_ext_format_lockdiscovery(ngx_http_request_t *r, u_char *dst,
18671873
return len;
18681874
}
18691875

1870-
if (entry->lock_root.len == 0) {
1876+
if (entry->lock_token == 0) {
18711877
dst = ngx_cpymem(dst, "<D:lockdiscovery/>\n",
18721878
sizeof("<D:lockdiscovery/>\n") - 1);
18731879
return (uintptr_t) dst;

0 commit comments

Comments
 (0)