Skip to content

Commit

Permalink
src: avoid returning invalid value from hex2bin
Browse files Browse the repository at this point in the history
If the input is not a valid hexadecimal digit, hex2bin should not return
an invalid value, which is not handled correctly by the caller, which is
the PercentDecode function. However, PercentDecode only ever calls the
hex2bin function with valid hexadecimal digits, so mark the code path
that previously returned an invalid value for non-digits as UNREACHABLE.

PR-URL: #42307
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
tniessen authored and danielleadams committed Apr 24, 2022
1 parent 2e42ccf commit 0e3e3fd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_url.cc
Expand Up @@ -230,7 +230,7 @@ unsigned hex2bin(const T ch) {
return 10 + (ch - 'A');
if (ch >= 'a' && ch <= 'f')
return 10 + (ch - 'a');
return static_cast<unsigned>(-1);
UNREACHABLE();
}

std::string PercentDecode(const char* input, size_t len) {
Expand Down

0 comments on commit 0e3e3fd

Please sign in to comment.