diff src/http/modules/ngx_http_memcached_module.c @ 322:d16d691432c9 NGINX_0_6_5

nginx 0.6.5 *) Feature: $nginx_version variable. Thanks to Nick S. Grechukh. *) Feature: the mail proxy supports AUTHENTICATE in IMAP mode. Thanks to Maxim Dounin. *) Feature: the mail proxy supports STARTTLS in SMTP mode. Thanks to Maxim Dounin. *) Bugfix: now nginx escapes space in $memcached_key variable. *) Bugfix: nginx was incorrectly built by Sun Studio on Solaris/amd64. Thanks to Jiang Hong. *) Bugfix: of minor potential bugs. Thanks to Coverity's Scan.
author Igor Sysoev <http://sysoev.ru>
date Mon, 23 Jul 2007 00:00:00 +0400
parents 95d92ec39071
children 9fc4ab6673f9
line wrap: on
line diff
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -226,6 +226,7 @@ static ngx_int_t
 ngx_http_memcached_create_request(ngx_http_request_t *r)
 {
     size_t                          len;
+    uintptr_t                       escape;
     ngx_buf_t                      *b;
     ngx_chain_t                    *cl;
     ngx_http_memcached_ctx_t       *ctx;
@@ -242,10 +243,9 @@ ngx_http_memcached_create_request(ngx_ht
         return NGX_ERROR;
     }
 
-    len = sizeof("get ") - 1 + vv->len + sizeof(CRLF) - 1;
-    if (vv->len) {
-        len += 1 + vv->len;
-    }
+    escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED);
+
+    len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1;
 
     b = ngx_create_temp_buf(r->pool, len);
     if (b == NULL) {
@@ -268,7 +268,13 @@ ngx_http_memcached_create_request(ngx_ht
 
     ctx->key.data = b->last;
 
-    b->last = ngx_copy(b->last, vv->data, vv->len);
+    if (escape == 0) {
+        b->last = ngx_copy(b->last, vv->data, vv->len);
+
+    } else {
+        b->last = (u_char *) ngx_escape_uri(b->last, vv->data, vv->len,
+                                            NGX_ESCAPE_MEMCACHED);
+    }
 
     ctx->key.len = b->last - ctx->key.data;