Skip to content

Commit

Permalink
no longer use the problematic ngx_strXcmp because it may cause invali…
Browse files Browse the repository at this point in the history
…d reads, thanks Piotr Sikora.
  • Loading branch information
agentzh committed Sep 14, 2010
1 parent e852769 commit da0211e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 55 deletions.
28 changes: 14 additions & 14 deletions src/ngx_http_echo_subrequest.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)

switch (method_name->len) {
case 3:
if (ngx_str3cmp(method_name->data, 'G', 'E', 'T')) {
if (ngx_http_echo_strcmp_const(method_name->data, "GET") == 0) {
*method_name_ptr = &ngx_http_echo_get_method;
return NGX_HTTP_GET;
break;
}

if (ngx_str3cmp(method_name->data, 'P', 'U', 'T')) {
if (ngx_http_echo_strcmp_const(method_name->data, "PUT") == 0) {
*method_name_ptr = &ngx_http_echo_put_method;
return NGX_HTTP_PUT;
break;
Expand All @@ -373,27 +373,27 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 4:
if (ngx_str4cmp(method_name->data, 'P', 'O', 'S', 'T')) {
if (ngx_http_echo_strcmp_const(method_name->data, "POST") == 0) {
*method_name_ptr = &ngx_http_echo_post_method;
return NGX_HTTP_POST;
break;
}
if (ngx_str4cmp(method_name->data, 'H', 'E', 'A', 'D')) {
if (ngx_http_echo_strcmp_const(method_name->data, "HEAD") == 0) {
*method_name_ptr = &ngx_http_echo_head_method;
return NGX_HTTP_HEAD;
break;
}
if (ngx_str4cmp(method_name->data, 'C', 'O', 'P', 'Y')) {
if (ngx_http_echo_strcmp_const(method_name->data, "COPY") == 0) {
*method_name_ptr = &ngx_http_echo_copy_method;
return NGX_HTTP_COPY;
break;
}
if (ngx_str4cmp(method_name->data, 'M', 'O', 'V', 'E')) {
if (ngx_http_echo_strcmp_const(method_name->data, "MOVE") == 0) {
*method_name_ptr = &ngx_http_echo_move_method;
return NGX_HTTP_MOVE;
break;
}
if (ngx_str4cmp(method_name->data, 'L', 'O', 'C', 'K')) {
if (ngx_http_echo_strcmp_const(method_name->data, "LOCK") == 0) {
*method_name_ptr = &ngx_http_echo_lock_method;
return NGX_HTTP_LOCK;
break;
Expand All @@ -402,12 +402,12 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 5:
if (ngx_strncmp("MKCOL", method_name->data, method_name->len) == 0) {
if (ngx_http_echo_strcmp_const(method_name->data, "MKCOL") == 0) {
*method_name_ptr = &ngx_http_echo_mkcol_method;
return NGX_HTTP_MKCOL;
break;
}
if (ngx_strncmp("TRACE", method_name->data, method_name->len) == 0) {
if (ngx_http_echo_strcmp_const(method_name->data, "TRACE") == 0) {
*method_name_ptr = &ngx_http_echo_trace_method;
return NGX_HTTP_TRACE;
break;
Expand All @@ -416,13 +416,13 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 6:
if (ngx_str6cmp(method_name->data, 'D', 'E', 'L', 'E', 'T', 'E')) {
if (ngx_http_echo_strcmp_const(method_name->data, "DELETE") == 0) {
*method_name_ptr = &ngx_http_echo_delete_method;
return NGX_HTTP_DELETE;
break;
}

if (ngx_str6cmp(method_name->data, 'U', 'N', 'L', 'O', 'C', 'K')) {
if (ngx_http_echo_strcmp_const(method_name->data, "UNLOCK") == 0) {
*method_name_ptr = &ngx_http_echo_unlock_method;
return NGX_HTTP_UNLOCK;
break;
Expand All @@ -431,7 +431,7 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 7:
if (ngx_strncmp("OPTIONS", method_name->data, method_name->len) == 0) {
if (ngx_http_echo_strcmp_const(method_name->data, "OPTIONS") == 0) {
*method_name_ptr = &ngx_http_echo_options_method;
return NGX_HTTP_OPTIONS;
break;
Expand All @@ -440,7 +440,7 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 8:
if (ngx_strncmp("PROPFIND", method_name->data, method_name->len) == 0) {
if (ngx_http_echo_strcmp_const(method_name->data, "PROPFIND") == 0) {
*method_name_ptr = &ngx_http_echo_propfind_method;
return NGX_HTTP_PROPFIND;
break;
Expand All @@ -449,7 +449,7 @@ ngx_http_echo_parse_method_name(ngx_str_t **method_name_ptr)
break;

case 9:
if (ngx_strncmp("PROPPATCH", method_name->data, method_name->len) == 0) {
if (ngx_http_echo_strcmp_const(method_name->data, "PROPPATCH") == 0) {
*method_name_ptr = &ngx_http_echo_proppatch_method;
return NGX_HTTP_PROPPATCH;
break;
Expand Down
43 changes: 2 additions & 41 deletions src/ngx_http_echo_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,8 @@

#include "ngx_http_echo_module.h"


#ifndef ngx_str4cmp

# if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)

# define ngx_str4cmp(m, c0, c1, c2, c3) \
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)

# else

# define ngx_str4cmp(m, c0, c1, c2, c3) \
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3

# endif

#endif /* ngx_str4cmp */

#ifndef ngx_str3cmp

# define ngx_str3cmp(m, c0, c1, c2) \
m[0] == c0 && m[1] == c1 && m[2] == c2

#endif /* ngx_str3cmp */

#ifndef ngx_str6cmp

# if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)

# define ngx_str6cmp(m, c0, c1, c2, c3, c4, c5) \
*(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0) \
&& (((uint32_t *) m)[1] & 0xffff) == ((c5 << 8) | c4)

# else

# define ngx_str6cmp(m, c0, c1, c2, c3, c4, c5) \
m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 \
&& m[4] == c4 && m[5] == c5

# endif

#endif /* ngx_str6cmp */
#define ngx_http_echo_strcmp_const(a, b) \
ngx_strncmp(a, b, sizeof(b) - 1)

ngx_int_t ngx_http_echo_init_ctx(ngx_http_request_t *r, ngx_http_echo_ctx_t **ctx_ptr);

Expand Down

0 comments on commit da0211e

Please sign in to comment.