about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-05T10·03-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-05T18·29+0000
commitf9df9b47339f3583741ccec9760dd8f3934bdee4 (patch)
tree21378c2efc81571462e0ed4321edba9413d2d3bb
parentf10d60a4543c39cb42f43159a18c9479e07ec56c (diff)
fix(3p/nix): fix usage error of absl::Base64Unescape r/1599
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 <grfn@gws.fyi>
-rw-r--r--third_party/nix/src/libstore/crypto.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/third_party/nix/src/libstore/crypto.cc b/third_party/nix/src/libstore/crypto.cc
index bec0b08c67c1..4661cbbb18fa 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<std::string, std::string> 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");
   }