From 9500e5862e41d5249080b11f675ad742cff8dd86 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) {