Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

converted CRLF in the source files and test files to LF. also fixed o…

…ne place that does not check the pointer returned by the memory allocator.
  • Loading branch information...
commit 290d6cbe19e859826c7a92299bb613a499130d86 1 parent 91997b2
@agentzh agentzh authored
View
144 src/ngx_http_set_hash.c
@@ -1,72 +1,72 @@
-#define DDEBUG 0
-#include "ddebug.h"
-
-#include "ngx_http_set_hash.h"
-#include "ngx_sha1.h"
-#include "ngx_md5.h"
-
-
-#ifndef SHA_DIGEST_LENGTH
-#define SHA_DIGEST_LENGTH 20
-#endif
-
-#ifndef MD5_DIGEST_LENGTH
-#define MD5_DIGEST_LENGTH 16
-#endif
-
-enum {
- SHA_HEX_LENGTH = SHA_DIGEST_LENGTH * 2,
- MD5_HEX_LENGTH = MD5_DIGEST_LENGTH * 2
-};
-
-
-ngx_int_t
-ngx_http_set_misc_set_sha1(ngx_http_request_t *r,
- ngx_str_t *res, ngx_http_variable_value_t *v)
-{
- u_char *p;
- ngx_sha1_t sha;
- u_char sha_buf[SHA_DIGEST_LENGTH];
-
- p = ngx_palloc(r->pool, SHA_HEX_LENGTH);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_sha1_init(&sha);
- ngx_sha1_update(&sha, v->data, v->len);
- ngx_sha1_final(sha_buf, &sha);
-
- ngx_hex_dump(p, sha_buf, sizeof(sha_buf));
-
- res->data = p;
- res->len = SHA_HEX_LENGTH;
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_set_misc_set_md5(ngx_http_request_t *r,
- ngx_str_t *res, ngx_http_variable_value_t *v)
-{
- u_char *p;
- ngx_md5_t md5;
- u_char md5_buf[MD5_DIGEST_LENGTH];
-
- p = ngx_palloc(r->pool, MD5_HEX_LENGTH);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_md5_init(&md5);
- ngx_md5_update(&md5, v->data, v->len);
- ngx_md5_final(md5_buf, &md5);
-
- ngx_hex_dump(p, md5_buf, sizeof(md5_buf));
-
- res->data = p;
- res->len = MD5_HEX_LENGTH;
-
- return NGX_OK;
-}
+#define DDEBUG 0
+#include "ddebug.h"
+
+#include "ngx_http_set_hash.h"
+#include "ngx_sha1.h"
+#include "ngx_md5.h"
+
+
+#ifndef SHA_DIGEST_LENGTH
+#define SHA_DIGEST_LENGTH 20
+#endif
+
+#ifndef MD5_DIGEST_LENGTH
+#define MD5_DIGEST_LENGTH 16
+#endif
+
+enum {
+ SHA_HEX_LENGTH = SHA_DIGEST_LENGTH * 2,
+ MD5_HEX_LENGTH = MD5_DIGEST_LENGTH * 2
+};
+
+
+ngx_int_t
+ngx_http_set_misc_set_sha1(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ u_char *p;
+ ngx_sha1_t sha;
+ u_char sha_buf[SHA_DIGEST_LENGTH];
+
+ p = ngx_palloc(r->pool, SHA_HEX_LENGTH);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_sha1_init(&sha);
+ ngx_sha1_update(&sha, v->data, v->len);
+ ngx_sha1_final(sha_buf, &sha);
+
+ ngx_hex_dump(p, sha_buf, sizeof(sha_buf));
+
+ res->data = p;
+ res->len = SHA_HEX_LENGTH;
+
+ return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_http_set_misc_set_md5(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ u_char *p;
+ ngx_md5_t md5;
+ u_char md5_buf[MD5_DIGEST_LENGTH];
+
+ p = ngx_palloc(r->pool, MD5_HEX_LENGTH);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_md5_init(&md5);
+ ngx_md5_update(&md5, v->data, v->len);
+ ngx_md5_final(md5_buf, &md5);
+
+ ngx_hex_dump(p, md5_buf, sizeof(md5_buf));
+
+ res->data = p;
+ res->len = MD5_HEX_LENGTH;
+
+ return NGX_OK;
+}
View
615 src/ngx_http_set_quote_sql.c
@@ -1,305 +1,310 @@
-#define DDEBUG 0
-
-#include "ddebug.h"
-#include <ndk.h>
-#include "ngx_http_set_quote_sql.h"
-
-
-ngx_int_t
-ngx_http_set_misc_quote_pgsql_str(ngx_http_request_t *r,
- ngx_str_t *res, ngx_http_variable_value_t *v)
-{
- u_char *pstr;
- ngx_int_t length;
-
- if (v->not_found || v->len ==0) {
- res->data = (u_char *) "''";
- res->len = sizeof("''") - 1;
- return NGX_OK;
- }
-
- ngx_http_set_misc_quote_sql_str(r, res, v);
- length = res->len;
- pstr = ngx_palloc(r->pool, length + 1);
- *pstr = 'E';
- memcpy(pstr + 1, res->data, length);
- res->data = pstr;
- res->len = length + 1;
-
- if (ngx_http_pg_utf_islegal(res->data, res->len)) {
- return NGX_OK;
- }
-
- res = ngx_http_pg_utf_escape(r, res);
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_pg_utf_mblen(const unsigned char *s)
-{
- int len;
-
- if ((*s & 0x80) == 0)
- len = 1;
- else if ((*s & 0xe0) == 0xc0)
- len = 2;
- else if ((*s & 0xf0) == 0xe0)
- len = 3;
- else if ((*s & 0xf8) == 0xf0)
- len = 4;
-#ifdef NOT_USED
- else if ((*s & 0xfc) == 0xf8)
- len = 5;
- else if ((*s & 0xfe) == 0xfc)
- len = 6;
-#endif
- else
- len = 1;
- return len;
-}
-
-
-ngx_int_t
-ngx_http_pg_utf_islegal(const unsigned char *s, ngx_int_t len)
-{
- ngx_int_t mblen;
- ngx_int_t slen;
- u_char a;
-
- slen = len;
-
- while (slen > 0) {
- mblen = ngx_http_pg_utf_mblen(s);
- if (slen < mblen)
- return 0;
-
- switch(mblen)
- {
- default:
- return 0;
- case 4:
- a = *(s + 3);
- if (a < 0x80 || a > 0xBF)
- return 0;
- case 3:
- a = *(s + 2);
- if (a < 0x80 || a > 0xBF)
- return 0;
- case 2:
- a = *(s + 1);
- switch (*s)
- {
- case 0xE0:
- if (a < 0xA0 || a > 0xBF)
- return 0;
- break;
- case 0xED:
- if (a < 0x80 || a > 0x9F)
- return 0;
- break;
- case 0xF0:
- if (a < 0x90 || a > 0xBF)
- return 0;
- break;
- case 0xF4:
- if (a < 0x80 || a > 0x8F)
- return 0;
- break;
- default:
- if (a < 0x80 || a > 0xBF)
- return 0;
- break;
- }
- case 1:
- a = *s;
- if (a >= 0x80 && a < 0xC2)
- return 0;
- if (a > 0xF4)
- return 0;
- break;
- }
-
- s += mblen;
- slen -= mblen;
- }
-
- return 1;
-}
-
-
-ngx_str_t *
-ngx_http_pg_utf_escape(ngx_http_request_t *r, ngx_str_t *res)
-{
- ngx_str_t *result;
- ngx_int_t l, count;
- u_char *d, *p, *p1;
-
- l = res->len;
- d = res->data;
- result = res;
- count = 0;
-
- while (l-- > 0) {
- if (*d & 0x80) {
- count += 4;
- }
- d++;
- count++;
- }
-
- d = res->data;
- l = res->len;
-
- p = ngx_palloc(r->pool, count);
- if (p == NULL) {
- return result;
- }
-
- p1 = p;
- while (l-- > 0) {
- if ((*d & 0x80)) {
- *p++ = '\\';
- *p++ = '\\';
- *p++ = (*d >> 6) + '0';
- *p++ = ((*d >> 3) & 07) + '0';
- *p++ = (*d & 07) + '0';
- } else {
- *p++ = *d;
- }
- d++;
- }
-
- result->len = count;
- result->data = p1;
-
- return result;
-}
-
-
-ngx_int_t
-ngx_http_set_misc_quote_sql_str(ngx_http_request_t *r,
- ngx_str_t *res, ngx_http_variable_value_t *v)
-{
- size_t len;
- u_char *p;
- size_t escape;
-
- if (v->not_found || v->len == 0) {
- res->data = (u_char *) "''";
- res->len = sizeof("''") - 1;
- return NGX_OK;
- }
-
- escape = ngx_http_set_misc_escape_sql_str(NULL, v->data, v->len);
-
- len = sizeof("''") - 1 + v->len + escape;
-
- p = ngx_palloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- res->data = p;
- res->len = len;
-
- *p++ = '\'';
-
- if (escape == 0) {
- p = ngx_copy(p, v->data, v->len);
- } else {
- p = (u_char *) ngx_http_set_misc_escape_sql_str(p, v->data, v->len);
- }
-
- *p++ = '\'';
-
- if (p != res->data + res->len) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "set_quote_sql_str: buffer error");
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-uintptr_t
-ngx_http_set_misc_escape_sql_str(u_char *dst, u_char *src,
- size_t size)
-{
- ngx_uint_t n;
-
- if (dst == NULL) {
- /* find the number of chars to be escaped */
- n = 0;
- while (size) {
- /* the highest bit of all the UTF-8 chars
- * is always 1 */
- if ((*src & 0x80) == 0) {
- switch (*src) {
- case '\r':
- case '\n':
- case '\\':
- case '\'':
- case '"':
- case '\032':
- n++;
- break;
- default:
- break;
- }
- }
- src++;
- size--;
- }
-
- return (uintptr_t) n;
- }
-
- while (size) {
- if ((*src & 0x80) == 0) {
- switch (*src) {
- case '\r':
- *dst++ = '\\';
- *dst++ = 'r';
- break;
-
- case '\n':
- *dst++ = '\\';
- *dst++ = 'n';
- break;
-
- case '\\':
- *dst++ = '\\';
- *dst++ = '\\';
- break;
-
- case '\'':
- *dst++ = '\\';
- *dst++ = '\'';
- break;
-
- case '"':
- *dst++ = '\\';
- *dst++ = '"';
- break;
-
- case '\032':
- *dst++ = '\\';
- *dst++ = *src;
- break;
-
- default:
- *dst++ = *src;
- break;
- }
- } else {
- *dst++ = *src;
- }
- src++;
- size--;
- } /* while (size) */
-
- return (uintptr_t) dst;
-}
-
+#define DDEBUG 0
+
+#include "ddebug.h"
+#include <ndk.h>
+#include "ngx_http_set_quote_sql.h"
+
+
+ngx_int_t
+ngx_http_set_misc_quote_pgsql_str(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ u_char *pstr;
+ ngx_int_t length;
+
+ if (v->not_found || v->len ==0) {
+ res->data = (u_char *) "''";
+ res->len = sizeof("''") - 1;
+ return NGX_OK;
+ }
+
+ ngx_http_set_misc_quote_sql_str(r, res, v);
+ length = res->len;
+
+ pstr = ngx_palloc(r->pool, length + 1);
+ if (pstr == NULL) {
+ return NGX_ERROR;
+ }
+
+ *pstr = 'E';
+ memcpy(pstr + 1, res->data, length);
+ res->data = pstr;
+ res->len = length + 1;
+
+ if (ngx_http_pg_utf_islegal(res->data, res->len)) {
+ return NGX_OK;
+ }
+
+ res = ngx_http_pg_utf_escape(r, res);
+ return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_http_pg_utf_mblen(const unsigned char *s)
+{
+ int len;
+
+ if ((*s & 0x80) == 0)
+ len = 1;
+ else if ((*s & 0xe0) == 0xc0)
+ len = 2;
+ else if ((*s & 0xf0) == 0xe0)
+ len = 3;
+ else if ((*s & 0xf8) == 0xf0)
+ len = 4;
+#ifdef NOT_USED
+ else if ((*s & 0xfc) == 0xf8)
+ len = 5;
+ else if ((*s & 0xfe) == 0xfc)
+ len = 6;
+#endif
+ else
+ len = 1;
+ return len;
+}
+
+
+ngx_int_t
+ngx_http_pg_utf_islegal(const unsigned char *s, ngx_int_t len)
+{
+ ngx_int_t mblen;
+ ngx_int_t slen;
+ u_char a;
+
+ slen = len;
+
+ while (slen > 0) {
+ mblen = ngx_http_pg_utf_mblen(s);
+ if (slen < mblen)
+ return 0;
+
+ switch(mblen)
+ {
+ default:
+ return 0;
+ case 4:
+ a = *(s + 3);
+ if (a < 0x80 || a > 0xBF)
+ return 0;
+ case 3:
+ a = *(s + 2);
+ if (a < 0x80 || a > 0xBF)
+ return 0;
+ case 2:
+ a = *(s + 1);
+ switch (*s)
+ {
+ case 0xE0:
+ if (a < 0xA0 || a > 0xBF)
+ return 0;
+ break;
+ case 0xED:
+ if (a < 0x80 || a > 0x9F)
+ return 0;
+ break;
+ case 0xF0:
+ if (a < 0x90 || a > 0xBF)
+ return 0;
+ break;
+ case 0xF4:
+ if (a < 0x80 || a > 0x8F)
+ return 0;
+ break;
+ default:
+ if (a < 0x80 || a > 0xBF)
+ return 0;
+ break;
+ }
+ case 1:
+ a = *s;
+ if (a >= 0x80 && a < 0xC2)
+ return 0;
+ if (a > 0xF4)
+ return 0;
+ break;
+ }
+
+ s += mblen;
+ slen -= mblen;
+ }
+
+ return 1;
+}
+
+
+ngx_str_t *
+ngx_http_pg_utf_escape(ngx_http_request_t *r, ngx_str_t *res)
+{
+ ngx_str_t *result;
+ ngx_int_t l, count;
+ u_char *d, *p, *p1;
+
+ l = res->len;
+ d = res->data;
+ result = res;
+ count = 0;
+
+ while (l-- > 0) {
+ if (*d & 0x80) {
+ count += 4;
+ }
+ d++;
+ count++;
+ }
+
+ d = res->data;
+ l = res->len;
+
+ p = ngx_palloc(r->pool, count);
+ if (p == NULL) {
+ return result;
+ }
+
+ p1 = p;
+ while (l-- > 0) {
+ if ((*d & 0x80)) {
+ *p++ = '\\';
+ *p++ = '\\';
+ *p++ = (*d >> 6) + '0';
+ *p++ = ((*d >> 3) & 07) + '0';
+ *p++ = (*d & 07) + '0';
+ } else {
+ *p++ = *d;
+ }
+ d++;
+ }
+
+ result->len = count;
+ result->data = p1;
+
+ return result;
+}
+
+
+ngx_int_t
+ngx_http_set_misc_quote_sql_str(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ size_t len;
+ u_char *p;
+ size_t escape;
+
+ if (v->not_found || v->len == 0) {
+ res->data = (u_char *) "''";
+ res->len = sizeof("''") - 1;
+ return NGX_OK;
+ }
+
+ escape = ngx_http_set_misc_escape_sql_str(NULL, v->data, v->len);
+
+ len = sizeof("''") - 1 + v->len + escape;
+
+ p = ngx_palloc(r->pool, len);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ res->data = p;
+ res->len = len;
+
+ *p++ = '\'';
+
+ if (escape == 0) {
+ p = ngx_copy(p, v->data, v->len);
+ } else {
+ p = (u_char *) ngx_http_set_misc_escape_sql_str(p, v->data, v->len);
+ }
+
+ *p++ = '\'';
+
+ if (p != res->data + res->len) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_quote_sql_str: buffer error");
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+}
+
+
+uintptr_t
+ngx_http_set_misc_escape_sql_str(u_char *dst, u_char *src,
+ size_t size)
+{
+ ngx_uint_t n;
+
+ if (dst == NULL) {
+ /* find the number of chars to be escaped */
+ n = 0;
+ while (size) {
+ /* the highest bit of all the UTF-8 chars
+ * is always 1 */
+ if ((*src & 0x80) == 0) {
+ switch (*src) {
+ case '\r':
+ case '\n':
+ case '\\':
+ case '\'':
+ case '"':
+ case '\032':
+ n++;
+ break;
+ default:
+ break;
+ }
+ }
+ src++;
+ size--;
+ }
+
+ return (uintptr_t) n;
+ }
+
+ while (size) {
+ if ((*src & 0x80) == 0) {
+ switch (*src) {
+ case '\r':
+ *dst++ = '\\';
+ *dst++ = 'r';
+ break;
+
+ case '\n':
+ *dst++ = '\\';
+ *dst++ = 'n';
+ break;
+
+ case '\\':
+ *dst++ = '\\';
+ *dst++ = '\\';
+ break;
+
+ case '\'':
+ *dst++ = '\\';
+ *dst++ = '\'';
+ break;
+
+ case '"':
+ *dst++ = '\\';
+ *dst++ = '"';
+ break;
+
+ case '\032':
+ *dst++ = '\\';
+ *dst++ = *src;
+ break;
+
+ default:
+ *dst++ = *src;
+ break;
+ }
+ } else {
+ *dst++ = *src;
+ }
+ src++;
+ size--;
+ } /* while (size) */
+
+ return (uintptr_t) dst;
+}
+
View
362 src/ngx_http_set_unescape_uri.c
@@ -1,181 +1,181 @@
-#define DDEBUG 0
-#include "ddebug.h"
-#include <ndk.h>
-#include "ngx_http_set_unescape_uri.h"
-
-#define NGX_UNESCAPE_URI_COMPONENT 0
-
-
-static void ngx_unescape_uri_patched(u_char **dst, u_char **src,
- size_t size, ngx_uint_t type);
-
-
-ngx_int_t
-ngx_http_set_misc_unescape_uri(ngx_http_request_t *r,
- ngx_str_t *res, ngx_http_variable_value_t *v)
-{
- size_t len;
- u_char *p;
- u_char *src, *dst;
-
- /* the unescaped string can only be smaller */
- len = v->len;
-
- p = ngx_palloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- src = v->data; dst = p;
-
- ngx_unescape_uri_patched(&dst, &src, v->len, NGX_UNESCAPE_URI_COMPONENT);
-
- if (src != v->data + v->len) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "set_unescape_uri: input data not consumed completely");
- return NGX_ERROR;
- }
-
- res->data = p;
- res->len = dst - p;
-
- return NGX_OK;
-}
-
-
-/* XXX we also decode '+' to ' ' */
-static void
-ngx_unescape_uri_patched(u_char **dst, u_char **src, size_t size,
- ngx_uint_t type)
-{
- u_char *d, *s, ch, c, decoded;
- enum {
- sw_usual = 0,
- sw_quoted,
- sw_quoted_second
- } state;
-
- d = *dst;
- s = *src;
-
- state = 0;
- decoded = 0;
-
- while (size--) {
-
- ch = *s++;
-
- switch (state) {
- case sw_usual:
- if (ch == '?'
- && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT)))
- {
- *d++ = ch;
- goto done;
- }
-
- if (ch == '%') {
- state = sw_quoted;
- break;
- }
-
- if (ch == '+') {
- *d++ = ' ';
- break;
- }
-
- *d++ = ch;
- break;
-
- case sw_quoted:
-
- if (ch >= '0' && ch <= '9') {
- decoded = (u_char) (ch - '0');
- state = sw_quoted_second;
- break;
- }
-
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'f') {
- decoded = (u_char) (c - 'a' + 10);
- state = sw_quoted_second;
- break;
- }
-
- /* the invalid quoted character */
-
- state = sw_usual;
-
- *d++ = ch;
-
- break;
-
- case sw_quoted_second:
-
- state = sw_usual;
-
- if (ch >= '0' && ch <= '9') {
- ch = (u_char) ((decoded << 4) + ch - '0');
-
- if (type & NGX_UNESCAPE_REDIRECT) {
- if (ch > '%' && ch < 0x7f) {
- *d++ = ch;
- break;
- }
-
- *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
-
- break;
- }
-
- *d++ = ch;
-
- break;
- }
-
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'f') {
- ch = (u_char) ((decoded << 4) + c - 'a' + 10);
-
- if (type & NGX_UNESCAPE_URI) {
- if (ch == '?') {
- *d++ = ch;
- goto done;
- }
-
- *d++ = ch;
- break;
- }
-
- if (type & NGX_UNESCAPE_REDIRECT) {
- if (ch == '?') {
- *d++ = ch;
- goto done;
- }
-
- if (ch > '%' && ch < 0x7f) {
- *d++ = ch;
- break;
- }
-
- *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
- break;
- }
-
- *d++ = ch;
-
- break;
- }
-
- /* the invalid quoted character */
-
- break;
- }
- }
-
-done:
-
- *dst = d;
- *src = s;
-}
-
+#define DDEBUG 0
+#include "ddebug.h"
+#include <ndk.h>
+#include "ngx_http_set_unescape_uri.h"
+
+#define NGX_UNESCAPE_URI_COMPONENT 0
+
+
+static void ngx_unescape_uri_patched(u_char **dst, u_char **src,
+ size_t size, ngx_uint_t type);
+
+
+ngx_int_t
+ngx_http_set_misc_unescape_uri(ngx_http_request_t *r,
+ ngx_str_t *res, ngx_http_variable_value_t *v)
+{
+ size_t len;
+ u_char *p;
+ u_char *src, *dst;
+
+ /* the unescaped string can only be smaller */
+ len = v->len;
+
+ p = ngx_palloc(r->pool, len);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ src = v->data; dst = p;
+
+ ngx_unescape_uri_patched(&dst, &src, v->len, NGX_UNESCAPE_URI_COMPONENT);
+
+ if (src != v->data + v->len) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "set_unescape_uri: input data not consumed completely");
+ return NGX_ERROR;
+ }
+
+ res->data = p;
+ res->len = dst - p;
+
+ return NGX_OK;
+}
+
+
+/* XXX we also decode '+' to ' ' */
+static void
+ngx_unescape_uri_patched(u_char **dst, u_char **src, size_t size,
+ ngx_uint_t type)
+{
+ u_char *d, *s, ch, c, decoded;
+ enum {
+ sw_usual = 0,
+ sw_quoted,
+ sw_quoted_second
+ } state;
+
+ d = *dst;
+ s = *src;
+
+ state = 0;
+ decoded = 0;
+
+ while (size--) {
+
+ ch = *s++;
+
+ switch (state) {
+ case sw_usual:
+ if (ch == '?'
+ && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT)))
+ {
+ *d++ = ch;
+ goto done;
+ }
+
+ if (ch == '%') {
+ state = sw_quoted;
+ break;
+ }
+
+ if (ch == '+') {
+ *d++ = ' ';
+ break;
+ }
+
+ *d++ = ch;
+ break;
+
+ case sw_quoted:
+
+ if (ch >= '0' && ch <= '9') {
+ decoded = (u_char) (ch - '0');
+ state = sw_quoted_second;
+ break;
+ }
+
+ c = (u_char) (ch | 0x20);
+ if (c >= 'a' && c <= 'f') {
+ decoded = (u_char) (c - 'a' + 10);
+ state = sw_quoted_second;
+ break;
+ }
+
+ /* the invalid quoted character */
+
+ state = sw_usual;
+
+ *d++ = ch;
+
+ break;
+
+ case sw_quoted_second:
+
+ state = sw_usual;
+
+ if (ch >= '0' && ch <= '9') {
+ ch = (u_char) ((decoded << 4) + ch - '0');
+
+ if (type & NGX_UNESCAPE_REDIRECT) {
+ if (ch > '%' && ch < 0x7f) {
+ *d++ = ch;
+ break;
+ }
+
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
+
+ break;
+ }
+
+ *d++ = ch;
+
+ break;
+ }
+
+ c = (u_char) (ch | 0x20);
+ if (c >= 'a' && c <= 'f') {
+ ch = (u_char) ((decoded << 4) + c - 'a' + 10);
+
+ if (type & NGX_UNESCAPE_URI) {
+ if (ch == '?') {
+ *d++ = ch;
+ goto done;
+ }
+
+ *d++ = ch;
+ break;
+ }
+
+ if (type & NGX_UNESCAPE_REDIRECT) {
+ if (ch == '?') {
+ *d++ = ch;
+ goto done;
+ }
+
+ if (ch > '%' && ch < 0x7f) {
+ *d++ = ch;
+ break;
+ }
+
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
+ break;
+ }
+
+ *d++ = ch;
+
+ break;
+ }
+
+ /* the invalid quoted character */
+
+ break;
+ }
+ }
+
+done:
+
+ *dst = d;
+ *src = s;
+}
+
View
178 t/default-value.t
@@ -1,89 +1,89 @@
-# vi:filetype=perl
-
-use lib 'lib';
-use Test::Nginx::Socket;
-
-#repeat_each(3);
-
-plan tests => repeat_each() * 2 * blocks();
-
-no_long_string();
-
-run_tests();
-
-#no_diff();
-
-__DATA__
-
-=== TEST 1: set if empty
---- config
- location /foo {
- set $a 32;
- set_if_empty $a 56;
- echo $a;
-
- set_if_empty $b 72;
- echo $b;
- }
---- request
-GET /foo
---- response_body
-32
-72
-
-
-
-=== TEST 2: set if empty
---- config
- location /foo {
- set $bar $arg_bar;
- set_if_empty $bar 15;
- echo $bar;
-
- set $bah $arg_bah;
- set_if_empty $bah 25;
- echo $bah;
- }
---- request
-GET /foo?bar=71
---- response_body
-71
-25
-
-
-
-=== TEST 3: set if empty
---- config
- location /foo {
- set $bar $arg_bar;
- set_if_empty $bar 15;
- echo $bar;
-
- set $bah $arg_bah;
- set_if_empty $bah 25;
- echo $bah;
- }
---- request
-GET /foo?bar=
---- response_body
-15
-25
-
-
-
-=== TEST 4: set if empty (using arg_xxx directly)
-buggy?
---- config
- location /foo {
- set_if_empty $arg_bar 15;
- echo $arg_bar;
-
- set_if_empty $arg_bah 25;
- echo $arg_bah;
- }
---- request
-GET /foo?bar=71
---- response_body
-71
-25
-
+# vi:filetype=perl
+
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#repeat_each(3);
+
+plan tests => repeat_each() * 2 * blocks();
+
+no_long_string();
+
+run_tests();
+
+#no_diff();
+
+__DATA__
+
+=== TEST 1: set if empty
+--- config
+ location /foo {
+ set $a 32;
+ set_if_empty $a 56;
+ echo $a;
+
+ set_if_empty $b 72;
+ echo $b;
+ }
+--- request
+GET /foo
+--- response_body
+32
+72
+
+
+
+=== TEST 2: set if empty
+--- config
+ location /foo {
+ set $bar $arg_bar;
+ set_if_empty $bar 15;
+ echo $bar;
+
+ set $bah $arg_bah;
+ set_if_empty $bah 25;
+ echo $bah;
+ }
+--- request
+GET /foo?bar=71
+--- response_body
+71
+25
+
+
+
+=== TEST 3: set if empty
+--- config
+ location /foo {
+ set $bar $arg_bar;
+ set_if_empty $bar 15;
+ echo $bar;
+
+ set $bah $arg_bah;
+ set_if_empty $bah 25;
+ echo $bah;
+ }
+--- request
+GET /foo?bar=
+--- response_body
+15
+25
+
+
+
+=== TEST 4: set if empty (using arg_xxx directly)
+buggy?
+--- config
+ location /foo {
+ set_if_empty $arg_bar 15;
+ echo $arg_bar;
+
+ set_if_empty $arg_bah 25;
+ echo $arg_bah;
+ }
+--- request
+GET /foo?bar=71
+--- response_body
+71
+25
+
View
23 valgrind.suppress
@@ -1,4 +1,27 @@
{
+ <insert_a_suppression_name_here>
+ exp-sgcheck:SorG
+ fun:ngx_http_variables_init_vars
+ fun:ngx_http_block
+}
+{
+ <insert_a_suppression_name_here>
+ exp-sgcheck:SorG
+ fun:ngx_conf_parse
+}
+{
+ <insert_a_suppression_name_here>
+ exp-sgcheck:SorG
+ fun:ngx_vslprintf
+ fun:ngx_log_error_core
+}
+{
+ <insert_a_suppression_name_here>
+ exp-sgcheck:SorG
+ fun:ngx_conf_parse
+ fun:ngx_http_core_location
+}
+{
nginx-core-process-init
Memcheck:Leak
fun:malloc
Please sign in to comment.
Something went wrong with that request. Please try again.