aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index 49e781980..aa50fceb9 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -106,7 +106,7 @@ Hash parseHash(HashType ht, const string & s)
string s2(s, i * 2, 2);
if (!isxdigit(s2[0]) || !isxdigit(s2[1]))
throw BadHash(format("invalid hash ‘%1%’") % s);
- istringstream_nocopy str(s2);
+ std::istringstream str(s2);
int n;
str >> std::hex >> n;
hash.hash[i] = n;
@@ -165,7 +165,13 @@ Hash parseHash32(HashType ht, const string & s)
unsigned int i = b / 8;
unsigned int j = b % 8;
hash.hash[i] |= digit << j;
- if (i < hash.hashSize - 1) hash.hash[i + 1] |= digit >> (8 - j);
+
+ if (i < hash.hashSize - 1) {
+ hash.hash[i + 1] |= digit >> (8 - j);
+ } else {
+ if (digit >> (8 - j))
+ throw BadHash(format("invalid base-32 hash ‘%1%’") % s);
+ }
}
return hash;