diff src/http/ngx_http_parse.c @ 6626:b3682580c1bd

Avoid left-shifting integers into the sign bit, which is undefined. Found with UndefinedBehaviorSanitizer.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 07 Jul 2016 21:02:28 +0300
parents 302ff40c9bc9
children 57148b755320
line wrap: on
line diff
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -481,7 +481,7 @@ ngx_http_parse_request_line(ngx_http_req
         /* check "/.", "//", "%", and "\" (Win32) in URI */
         case sw_after_slash_in_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 state = sw_check_uri;
                 break;
             }
@@ -540,7 +540,7 @@ ngx_http_parse_request_line(ngx_http_req
         /* check "/", "%" and "\" (Win32) in URI */
         case sw_check_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 break;
             }
 
@@ -626,7 +626,7 @@ ngx_http_parse_request_line(ngx_http_req
         /* URI */
         case sw_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 break;
             }
 
@@ -1131,7 +1131,7 @@ ngx_http_parse_uri(ngx_http_request_t *r
         /* check "/.", "//", "%", and "\" (Win32) in URI */
         case sw_after_slash_in_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 state = sw_check_uri;
                 break;
             }
@@ -1179,7 +1179,7 @@ ngx_http_parse_uri(ngx_http_request_t *r
         /* check "/", "%" and "\" (Win32) in URI */
         case sw_check_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 break;
             }
 
@@ -1228,7 +1228,7 @@ ngx_http_parse_uri(ngx_http_request_t *r
         /* URI */
         case sw_uri:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 break;
             }
 
@@ -1289,7 +1289,7 @@ ngx_http_parse_complex_uri(ngx_http_requ
 
         case sw_usual:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 *u++ = ch;
                 ch = *p++;
                 break;
@@ -1358,7 +1358,7 @@ ngx_http_parse_complex_uri(ngx_http_requ
 
         case sw_slash:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 state = sw_usual;
                 *u++ = ch;
                 ch = *p++;
@@ -1401,7 +1401,7 @@ ngx_http_parse_complex_uri(ngx_http_requ
 
         case sw_dot:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 state = sw_usual;
                 *u++ = ch;
                 ch = *p++;
@@ -1442,7 +1442,7 @@ ngx_http_parse_complex_uri(ngx_http_requ
 
         case sw_dot_dot:
 
-            if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+            if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
                 state = sw_usual;
                 *u++ = ch;
                 ch = *p++;
@@ -1836,7 +1836,7 @@ ngx_http_parse_unsafe_uri(ngx_http_reque
             continue;
         }
 
-        if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
+        if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
             continue;
         }