From 0e3e3fda22b7e26b9cd59d90dc882619a46845ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 14 Mar 2022 17:23:44 +0100 Subject: [PATCH] src: avoid returning invalid value from hex2bin 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: https://github.com/nodejs/node/pull/42307 Reviewed-By: Anna Henningsen Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- src/node_url.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_url.cc b/src/node_url.cc index 79476e7a2f6a95..2541b95aa0c70d 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -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(-1); + UNREACHABLE(); } std::string PercentDecode(const char* input, size_t len) {