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 bengl committed Mar 21, 2022
1 parent e17db8f commit 9500e58
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
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 9500e58

Please sign in to comment.