Skip to content

Pass unsigned char to the ctype calls in ExtensionsParser and ParameterParser - #1971

Open
Shrusti-pk wants to merge 1 commit into
uNetworking:masterfrom
Shrusti-pk:ctype-unsigned-char
Open

Shrusti-pk wants to merge 1 commit into
uNetworking:masterfrom
Shrusti-pk:ctype-unsigned-char

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

Two header parsers pass a plain char to <cctype>, so any byte from 0x80 to 0xFF becomes a negative int that is not EOF, which is undefined behaviour (C11 7.4p1). HttpParser accepts those bytes in field values, so both are reachable from a client:

  • ExtensionsParser::getToken (isalnum, isdigit) runs on Sec-WebSocket-Extensions during the upgrade, before any application code
  • ParameterParser::getToken (isspace) runs on the Content-Disposition line of a multipart part, where an unquoted UTF-8 filename=é.txt is enough

With the Windows UCRT (the clang++ setup of the build_windows job), a debug build asserts c >= -1 && c <= 255 in isctype.cpp for Sec-WebSocket-Extensions: permessage-deflate; <0xE9>client_max_window_bits and for the filename above. With the cast both parse the same as before and the assertion is gone. These are all the ctype calls in src/. glibc tolerates negative values, which is why the fuzzers don't see it, so there is no new test; tests/ExtensionsNegotiator, Query, HttpParser, ChunkedEncoding and BloomFilter still pass under ASan.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant