Skip to content
This repository
Browse code

no longer use the problematic ngx_strXcmp because it may cause invali…

…d reads, thanks Piotr Sikora.
  • Loading branch information...
commit a00a637915772cab07d782028eb5b3e22312e832 1 parent d1aa2c5
Yichun Zhang authored
18  src/ngx_http_drizzle_keepalive.c
@@ -35,7 +35,7 @@ ngx_http_upstream_drizzle_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
35 35
 
36 36
     for (i = 1; i < cf->args->nelts; i++) {
37 37
 
38  
-        if (ngx_strncmp(value[i].data, "max=", sizeof("max=") - 1)
  38
+        if (ngx_http_drizzle_strcmp_const(value[i].data, "max=")
39 39
                 == 0)
40 40
         {
41 41
             len = value[i].len - (sizeof("max=") - 1);
@@ -57,21 +57,19 @@ ngx_http_upstream_drizzle_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
57 57
             continue;
58 58
         }
59 59
 
60  
-        if (ngx_strncmp(value[i].data, "mode=", sizeof("mode=") - 1)
61  
-                == 0)
62  
-        {
  60
+        if (ngx_http_drizzle_strcmp_const(value[i].data, "mode=") == 0) {
63 61
             len = value[i].len - (sizeof("mode=") - 1);
64 62
             data = &value[i].data[sizeof("mode=") - 1];
65 63
 
66 64
             switch (len) {
67 65
             case 6:
68  
-                if (ngx_str6cmp(data, 's', 'i', 'n', 'g', 'l', 'e')) {
  66
+                if (ngx_http_drizzle_strcmp_const(data, "single") == 0) {
69 67
                     dscf->single = 1;
70 68
                 }
71 69
                 break;
72 70
 
73 71
             case 5:
74  
-                if (ngx_str5cmp(data, 'm', 'u', 'l', 't', 'i')) {
  72
+                if (ngx_http_drizzle_strcmp_const(data, "multi") == 0) {
75 73
                     dscf->single = 0;
76 74
                 }
77 75
                 break;
@@ -88,17 +86,15 @@ ngx_http_upstream_drizzle_keepalive(ngx_conf_t *cf, ngx_command_t *cmd,
88 86
             continue;
89 87
         }
90 88
 
91  
-        if (ngx_strncmp(value[i].data, "overflow=", sizeof("overflow=") - 1)
92  
-                == 0)
93  
-        {
  89
+        if (ngx_http_drizzle_strcmp_const(value[i].data, "overflow=") == 0) {
94 90
             len = value[i].len - (sizeof("overflow=") - 1);
95 91
             data = &value[i].data[sizeof("overflow=") - 1];
96 92
 
97 93
             switch (len) {
98 94
             case 6:
99  
-                if (ngx_str6cmp(data, 'r', 'e', 'j', 'e', 'c', 't')) {
  95
+                if (ngx_http_drizzle_strcmp_const(data, "reject") == 0) {
100 96
                     dscf->overflow = drizzle_keepalive_overflow_reject;
101  
-                } else if (ngx_str6cmp(data, 'i', 'g', 'n', 'o', 'r', 'e')) {
  97
+                } else if (ngx_http_drizzle_strcmp_const(data, "ignore") == 0) {
102 98
                     dscf->overflow = drizzle_keepalive_overflow_ignore;
103 99
                 }
104 100
                 break;
92  src/ngx_http_drizzle_util.h
@@ -7,6 +7,8 @@
7 7
 #include <ngx_core.h>
8 8
 #include <ngx_http.h>
9 9
 
  10
+#define ngx_http_drizzle_strcmp_const(a, b) \
  11
+        ngx_strncmp(a, b, sizeof(b) - 1)
10 12
 
11 13
 void ngx_http_upstream_dbd_init(ngx_http_request_t *r);
12 14
 
@@ -26,96 +28,6 @@ ngx_int_t ngx_http_upstream_drizzle_test_connect(ngx_connection_t *c);
26 28
 
27 29
 #define ngx_http_drizzle_nelems(x) (sizeof(x) / sizeof(x[0]))
28 30
 
29  
-#ifndef ngx_str3cmp
30  
-
31  
-#  define ngx_str3cmp(m, c0, c1, c2)                                       \
32  
-    m[0] == c0 && m[1] == c1 && m[2] == c2
33  
-
34  
-#endif /* ngx_str3cmp */
35  
-
36  
-
37  
-#ifndef ngx_str4cmp
38  
-
39  
-#  if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
40  
-
41  
-#    define ngx_str4cmp(m, c0, c1, c2, c3)                                        \
42  
-    *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)
43  
-
44  
-#  else
45  
-
46  
-#    define ngx_str4cmp(m, c0, c1, c2, c3)                                        \
47  
-    m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3
48  
-
49  
-#  endif
50  
-
51  
-#endif /* ngx_str4cmp */
52  
-
53  
-
54  
-#ifndef ngx_str5cmp
55  
-
56  
-#  if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
57  
-
58  
-#    define ngx_str5cmp(m, c0, c1, c2, c3, c4)                                    \
59  
-    *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)             \
60  
-        && m[4] == c4
61  
-
62  
-#  else
63  
-
64  
-#    define ngx_str5cmp(m, c0, c1, c2, c3, c4)                                    \
65  
-    m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3 && m[4] == c4
66  
-
67  
-#  endif
68  
-
69  
-#endif /* ngx_str5cmp */
70  
-
71  
-
72  
-#ifndef ngx_str6cmp
73  
-
74  
-#  if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
75  
-
76  
-#    define ngx_str6cmp(m, c0, c1, c2, c3, c4, c5)                                \
77  
-    *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)             \
78  
-        && (((uint32_t *) m)[1] & 0xffff) == ((c5 << 8) | c4)
79  
-
80  
-#  else
81  
-
82  
-#    define ngx_str6cmp(m, c0, c1, c2, c3, c4, c5)                                \
83  
-    m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3                      \
84  
-        && m[4] == c4 && m[5] == c5
85  
-
86  
-#  endif
87  
-
88  
-#endif /* ngx_str6cmp */
89  
-
90  
-
91  
-#ifndef ngx_str7cmp
92  
-
93  
-#  define ngx_str7cmp(m, c0, c1, c2, c3, c4, c5, c6)                          \
94  
-    m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3                      \
95  
-        && m[4] == c4 && m[5] == c5 && m[6] == c6
96  
-
97  
-#endif /* ngx_str7cmp */
98  
-
99  
-
100  
-#ifndef ngx_str9cmp
101  
-
102  
-#  if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
103  
-
104  
-#    define ngx_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8)                    \
105  
-    *(uint32_t *) m == ((c3 << 24) | (c2 << 16) | (c1 << 8) | c0)             \
106  
-        && ((uint32_t *) m)[1] == ((c7 << 24) | (c6 << 16) | (c5 << 8) | c4)  \
107  
-        && m[8] == c8
108  
-
109  
-#  else
110  
-
111  
-#    define ngx_str9cmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8)                    \
112  
-    m[0] == c0 && m[1] == c1 && m[2] == c2 && m[3] == c3                      \
113  
-        && m[4] == c4 && m[5] == c5 && m[6] == c6 && m[7] == c7 && m[8] == c8
114  
-
115  
-#  endif
116  
-
117  
-
118  
-#endif /* ngx_str9cmp */
119 31
 
120 32
 #endif /* NGX_HTTP_DRIZZLE_UTIL_H */
121 33
 
6  src/ngx_http_upstream_drizzle.c
@@ -204,7 +204,7 @@ ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
204 204
 
205 205
             switch (protocol.len) {
206 206
             case 5:
207  
-                if (ngx_str5cmp(protocol.data, 'm', 'y', 's', 'q', 'l')) {
  207
+                if (ngx_http_drizzle_strcmp_const(protocol.data, "mysql") == 0) {
208 208
                     ds->protocol = ngx_http_mysql_protocol;
209 209
                 } else {
210 210
                     continue;
@@ -213,8 +213,8 @@ ngx_http_upstream_drizzle_server(ngx_conf_t *cf, ngx_command_t *cmd,
213 213
                 break;
214 214
 
215 215
             case 7:
216  
-                if ( ! ngx_str7cmp(protocol.data,
217  
-                            'd', 'r', 'i', 'z', 'z', 'l', 'e'))
  216
+                if (ngx_http_drizzle_strcmp_const(protocol.data,
  217
+                            "drizzle") != 0)
218 218
                 {
219 219
                     continue;
220 220
                 }

0 notes on commit a00a637

Please sign in to comment.
Something went wrong with that request. Please try again.