1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-08 02:43:54 +02:00

Merge pull request #12190 from NixOS/mergify/bp/2.24-maintenance/pr-11813

fix(libstore-tests): remove use-after-free bug for `StringSource` (backport #11813)
This commit is contained in:
mergify[bot] 2025-01-10 19:34:56 +00:00 committed by GitHub
commit 51e41edbef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 22 deletions

View file

@ -2,6 +2,7 @@
///@file
#include <memory>
#include <type_traits>
#include "types.hh"
#include "util.hh"
@ -192,7 +193,14 @@ struct StringSource : Source
{
std::string_view s;
size_t pos;
// NOTE: Prevent unintentional dangling views when an implicit conversion
// from std::string -> std::string_view occurs when the string is passed
// by rvalue.
StringSource(std::string &&) = delete;
StringSource(std::string_view s) : s(s), pos(0) { }
StringSource(const std::string& str): StringSource(std::string_view(str)) {}
size_t read(char * data, size_t len) override;
};