Skip to content

Commit

Permalink
Avoid left-shifting integers into the sign bit, which is undefined.
Browse files Browse the repository at this point in the history
Found with UndefinedBehaviorSanitizer.
  • Loading branch information
pluknet committed Jul 7, 2016
1 parent 678991a commit 6299f5e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/core/ngx_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
n = 0;

while (size) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
if (escape[*src >> 5] & (1U << (*src & 0x1f))) {
n++;
}
src++;
Expand All @@ -1574,7 +1574,7 @@ ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
}

while (size) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
if (escape[*src >> 5] & (1U << (*src & 0x1f))) {
*dst++ = '%';
*dst++ = hex[*src >> 4];
*dst++ = hex[*src & 0xf];
Expand Down
4 changes: 2 additions & 2 deletions src/http/modules/ngx_http_log_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ ngx_http_log_escape(u_char *dst, u_char *src, size_t size)
n = 0;

while (size) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
if (escape[*src >> 5] & (1U << (*src & 0x1f))) {
n++;
}
src++;
Expand All @@ -1011,7 +1011,7 @@ ngx_http_log_escape(u_char *dst, u_char *src, size_t size)
}

while (size) {
if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
if (escape[*src >> 5] & (1U << (*src & 0x1f))) {
*dst++ = '\\';
*dst++ = 'x';
*dst++ = hex[*src >> 4];
Expand Down
2 changes: 1 addition & 1 deletion src/http/modules/ngx_http_userid_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ ngx_http_userid_init_worker(ngx_cycle_t *cycle)
ngx_gettimeofday(&tp);

/* use the most significant usec part that fits to 16 bits */
start_value = ((tp.tv_usec / 20) << 16) | ngx_pid;
start_value = (((uint32_t) tp.tv_usec / 20) << 16) | ngx_pid;

return NGX_OK;
}
22 changes: 11 additions & 11 deletions src/http/ngx_http_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
/* 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;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
/* check "/", "%" and "\" (Win32) in URI */
case sw_check_uri:

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
break;
}

Expand Down Expand Up @@ -626,7 +626,7 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
/* URI */
case sw_uri:

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
break;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1289,7 +1289,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)

case sw_usual:

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
*u++ = ch;
ch = *p++;
break;
Expand Down Expand Up @@ -1358,7 +1358,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)

case sw_slash:

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
state = sw_usual;
*u++ = ch;
ch = *p++;
Expand Down Expand Up @@ -1401,7 +1401,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)

case sw_dot:

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
state = sw_usual;
*u++ = ch;
ch = *p++;
Expand Down Expand Up @@ -1442,7 +1442,7 @@ ngx_http_parse_complex_uri(ngx_http_request_t *r, ngx_uint_t merge_slashes)

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++;
Expand Down Expand Up @@ -1836,7 +1836,7 @@ ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
continue;
}

if (usual[ch >> 5] & (1 << (ch & 0x1f))) {
if (usual[ch >> 5] & (1U << (ch & 0x1f))) {
continue;
}

Expand Down

0 comments on commit 6299f5e

Please sign in to comment.