From e109d0747442faab5beb2dfa44163b97e6adeb69 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 7 Jan 2024 06:20:56 +0900 Subject: [PATCH] src: do not read string out of bounds PR-URL: https://github.com/nodejs/node/pull/51358 Reviewed-By: Yagiz Nizipli Reviewed-By: Keyhan Vakil Reviewed-By: Jiawen Geng --- src/path.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/path.cc b/src/path.cc index 250faf05bab71e..6a56b750d6e947 100644 --- a/src/path.cc +++ b/src/path.cc @@ -24,15 +24,14 @@ std::string NormalizeString(const std::string_view path, int lastSegmentLength = 0; int lastSlash = -1; int dots = 0; - char code; - const auto pathLen = path.size(); - for (uint8_t i = 0; i <= pathLen; ++i) { - if (i < pathLen) { + char code = 0; + for (size_t i = 0; i <= path.size(); ++i) { + if (i < path.size()) { code = path[i]; - } else if (IsPathSeparator(path[i])) { + } else if (IsPathSeparator(code)) { break; } else { - code = node::kPathSeparator; + code = '/'; } if (IsPathSeparator(code)) {