Skip to content

Commit

Permalink
Fixed incorrect length handling in ngx_utf8_length().
Browse files Browse the repository at this point in the history
Previously, ngx_utf8_decode() was called from ngx_utf8_length() with
incorrect length, potentially resulting in out-of-bounds read when
handling invalid UTF-8 strings.

In practice out-of-bounds reads are not possible though, as autoindex, the
only user of ngx_utf8_length(), provides null-terminated strings, and
ngx_utf8_decode() anyway returns an errors when it sees a null in the
middle of an UTF-8 sequence.

Reported by Yunbin Liu.
  • Loading branch information
mdounin committed Apr 15, 2019
1 parent 5784889 commit f09eae2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/ngx_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ ngx_utf8_length(u_char *p, size_t n)
continue;
}

if (ngx_utf8_decode(&p, n) > 0x10ffff) {
if (ngx_utf8_decode(&p, last - p) > 0x10ffff) {
/* invalid UTF-8 */
return n;
}
Expand Down

0 comments on commit f09eae2

Please sign in to comment.