Merge pull request #8936 from NixOS/backport-8825-to-2.17-maintenance

[Backport 2.17-maintenance] src/libexpr/search-path.cc: avoid out-of-bounds read on string_view
This commit is contained in:
Eelco Dolstra 2023-09-07 08:11:57 +02:00 committed by GitHub
commit 2da46530d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ std::optional<std::string_view> SearchPath::Prefix::suffixIfPotentialMatch(
/* Non-empty prefix and suffix must be separated by a /, or the
prefix is not a valid path prefix. */
bool needSeparator = n > 0 && (path.size() - n) > 0;
bool needSeparator = n > 0 && n < path.size();
if (needSeparator && path[n] != '/') {
return std::nullopt;