1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 02:21:16 +02:00

fromJSON/fromTOML: throw if string contains null byte

This commit is contained in:
Philipp Otterbein 2024-12-07 20:46:11 +01:00
parent ab5a9cf2db
commit 3a9d64b8e3
12 changed files with 60 additions and 3 deletions

View file

@ -3178,5 +3178,14 @@ std::ostream & operator << (std::ostream & str, const ExternalValueBase & v) {
return v.print(str);
}
void forceNoNullByte(std::string_view s)
{
if (s.find('\0') != s.npos) {
using namespace std::string_view_literals;
auto str = replaceStrings(std::string(s), "\0"sv, ""sv);
throw Error("input string '%s' cannot be represented as Nix string because it contains null bytes", str);
}
}
}