diff options
author | Kane York <kanepyork@gmail.com> | 2020-08-01T00·37-0700 |
---|---|---|
committer | kanepyork <rikingcoding@gmail.com> | 2020-08-01T01·15+0000 |
commit | 674dbade27040c0d8e8cbfbd9313afd4866e3e13 (patch) | |
tree | 19cf71da39a0df77fe8b5d5994726f062cc5c10d /third_party/nix/src | |
parent | 1cbffe21f3284fbad10b4ca27b0d8381bd554ff3 (diff) |
fix(3p/nix/hash): param of Unknown allows any hash type r/1516
Fixes a crash in the self-hosting instantiate test: NIX_REMOTE="$(mktemp -d)" nix-instantiate -E 'let depot = import ./default.nix {}; in depot.third_party.nix.outPath' Change-Id: If99494aa07ec248d3894d4709ab0fde7fa81aff3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1508 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'third_party/nix/src')
-rw-r--r-- | third_party/nix/src/libutil/hash.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index 44fc4323b337..0d5a1de07ce7 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -6,6 +6,7 @@ #include <absl/strings/escaping.h> #include <absl/strings/str_format.h> #include <fcntl.h> +#include <glog/logging.h> #include <openssl/md5.h> #include <openssl/sha.h> #include <sys/stat.h> @@ -182,6 +183,7 @@ Hash::Hash(std::string_view s, HashType type) : type(type) { *this = unwrap_throw(result); } +// TODO(riking): change ht to an optional absl::StatusOr<Hash> Hash::deserialize(std::string_view s, HashType type) { size_t pos = 0; bool isSRI = false; @@ -201,7 +203,7 @@ absl::StatusOr<Hash> Hash::deserialize(std::string_view s, HashType type) { if (sep != std::string::npos) { std::string hts = std::string(s, 0, sep); parsedType = parseHashType(hts); - if (parsedType != type) { + if (type != htUnknown && parsedType != type) { return absl::InvalidArgumentError( absl::StrCat("hash '", s, "' should have type '", printHashType(type), "', found '", printHashType(parsedType), "'")); @@ -432,7 +434,10 @@ std::string printHashType(HashType ht) { return "sha256"; } else if (ht == htSHA512) { return "sha512"; + } else if (ht == htUnknown) { + return "<unknown>"; } else { + LOG(FATAL) << "Unrecognized hash type: " << static_cast<int>(ht); abort(); } } |