From f9df9b47339f3583741ccec9760dd8f3934bdee4 Mon Sep 17 00:00:00 2001 From: Kane York Date: Wed, 5 Aug 2020 03:03:06 -0700 Subject: fix(3p/nix): fix usage error of absl::Base64Unescape The source and destination strings cannot be the same string - absl will write to the destination in a streaming manner, causing the source to become invalid. Change-Id: I3578cf1f8789a51d85e0950f7987c398f0a00953 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1659 Tested-by: BuildkiteCI Reviewed-by: glittershark --- third_party/nix/src/libstore/crypto.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/third_party/nix/src/libstore/crypto.cc b/third_party/nix/src/libstore/crypto.cc index bec0b08c67..4661cbbb18 100644 --- a/third_party/nix/src/libstore/crypto.cc +++ b/third_party/nix/src/libstore/crypto.cc @@ -11,6 +11,7 @@ namespace nix { +// TODO(riking): convert to string_view to reduce allocations static std::pair split(const std::string& s) { size_t colon = s.find(':'); if (colon == std::string::npos || colon == 0) { @@ -23,13 +24,13 @@ Key::Key(const std::string& s) { auto ss = split(s); name = ss.first; - key = ss.second; + std::string keyb64 = ss.second; - if (name.empty() || key.empty()) { + if (name.empty() || keyb64.empty()) { throw Error("secret key is corrupt"); } - if (!absl::Base64Unescape(key, &key)) { + if (!absl::Base64Unescape(keyb64, &key)) { // TODO(grfn): replace this with StatusOr throw Error("Invalid Base64"); } -- cgit 1.4.1