comparison src/http/ngx_http_script.c @ 1891:782af1038115

length calculation did not take into account escaped symbols in arguments
author Igor Sysoev <igor@sysoev.ru>
date Tue, 12 Feb 2008 18:05:32 +0000
parents 0b5b94805d26
children 2a92804f4109 0434fd856a2f
comparison
equal deleted inserted replaced
1890:d51ea7f11bc3 1891:782af1038115
219 219
220 if (sc->source->data[i] == '?' && sc->compile_args) { 220 if (sc->source->data[i] == '?' && sc->compile_args) {
221 sc->args = 1; 221 sc->args = 1;
222 sc->compile_args = 0; 222 sc->compile_args = 0;
223 223
224 code = ngx_http_script_add_code(*sc->lengths, sizeof(uintptr_t),
225 NULL);
226 if (code == NULL) {
227 return NGX_ERROR;
228 }
229
230 *code = (uintptr_t) ngx_http_script_mark_args_code;
231
224 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t), 232 code = ngx_http_script_add_code(*sc->values, sizeof(uintptr_t),
225 &sc->main); 233 &sc->main);
226 if (code == NULL) { 234 if (code == NULL) {
227 return NGX_ERROR; 235 return NGX_ERROR;
228 } 236 }
502 code = (ngx_http_script_copy_capture_code_t *) e->ip; 510 code = (ngx_http_script_copy_capture_code_t *) e->ip;
503 511
504 e->ip += sizeof(ngx_http_script_copy_capture_code_t); 512 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
505 513
506 if (code->n < e->ncaptures) { 514 if (code->n < e->ncaptures) {
507 if ((e->args || e->quote) 515 if ((e->is_args || e->quote)
508 && (e->request->quoted_uri || e->request->plus_in_uri)) 516 && (e->request->quoted_uri || e->request->plus_in_uri))
509 { 517 {
510 return e->captures[code->n + 1] - e->captures[code->n] 518 return e->captures[code->n + 1] - e->captures[code->n]
511 + 2 * ngx_escape_uri(NULL, 519 + 2 * ngx_escape_uri(NULL,
512 &e->line.data[e->captures[code->n]], 520 &e->line.data[e->captures[code->n]],
529 code = (ngx_http_script_copy_capture_code_t *) e->ip; 537 code = (ngx_http_script_copy_capture_code_t *) e->ip;
530 538
531 e->ip += sizeof(ngx_http_script_copy_capture_code_t); 539 e->ip += sizeof(ngx_http_script_copy_capture_code_t);
532 540
533 if (code->n < e->ncaptures) { 541 if (code->n < e->ncaptures) {
534 if ((e->args || e->quote) 542 if ((e->is_args || e->quote)
535 && (e->request->quoted_uri || e->request->plus_in_uri)) 543 && (e->request->quoted_uri || e->request->plus_in_uri))
536 { 544 {
537 e->pos = (u_char *) ngx_escape_uri(e->pos, 545 e->pos = (u_char *) ngx_escape_uri(e->pos,
538 &e->line.data[e->captures[code->n]], 546 &e->line.data[e->captures[code->n]],
539 e->captures[code->n + 1] - e->captures[code->n], 547 e->captures[code->n + 1] - e->captures[code->n],
548 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, 556 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
549 "http script capture: \"%V\"", &e->buf); 557 "http script capture: \"%V\"", &e->buf);
550 } 558 }
551 559
552 560
561 size_t
562 ngx_http_script_mark_args_code(ngx_http_script_engine_t *e)
563 {
564 e->is_args = 1;
565 e->ip += sizeof(uintptr_t);
566
567 return 1;
568 }
569
570
553 void 571 void
554 ngx_http_script_start_args_code(ngx_http_script_engine_t *e) 572 ngx_http_script_start_args_code(ngx_http_script_engine_t *e)
555 { 573 {
556 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, 574 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
557 "http script args"); 575 "http script args");
698 le.request = r; 716 le.request = r;
699 le.captures = e->captures; 717 le.captures = e->captures;
700 le.ncaptures = e->ncaptures; 718 le.ncaptures = e->ncaptures;
701 le.quote = code->redirect; 719 le.quote = code->redirect;
702 720
703 len = 1; /* reserve 1 byte for possible "?" */ 721 len = 0;
704 722
705 while (*(uintptr_t *) le.ip) { 723 while (*(uintptr_t *) le.ip) {
706 lcode = *(ngx_http_script_len_code_pt *) le.ip; 724 lcode = *(ngx_http_script_len_code_pt *) le.ip;
707 len += lcode(&le); 725 len += lcode(&le);
708 } 726 }
709 727
710 e->buf.len = len; 728 e->buf.len = len;
729 e->is_args = le.is_args;
711 } 730 }
712 731
713 if (code->add_args && r->args.len) { 732 if (code->add_args && r->args.len) {
714 e->buf.len += r->args.len + 1; 733 e->buf.len += r->args.len + 1;
715 } 734 }