aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2022-04-08 23:17:01 -0400
committerMacroFake <falke.marco@gmail.com>2022-04-27 14:12:55 +0200
commita4377a0843636eae0aaf698510fc6518582545db (patch)
treeb89dfb8794880401981929fef7e1e6b211ad46e6 /src/util/strencodings.cpp
parentd648b5120b2fefa9e599898bd26f05ecf4428fac (diff)
Reject incorrect base64 in HTTP auth
In addition, to make sure that no call site ignores the invalid decoding status, make the pf_invalid argument mandatory.
Diffstat (limited to 'src/util/strencodings.cpp')
-rw-r--r--src/util/strencodings.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 6346bc0811..6b6644aa9f 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -167,7 +167,7 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
++p;
}
valid = valid && (p - e) % 4 == 0 && p - q < 4;
- if (pf_invalid) *pf_invalid = !valid;
+ *pf_invalid = !valid;
return ret;
}
@@ -175,9 +175,7 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
std::string DecodeBase64(const std::string& str, bool* pf_invalid)
{
if (!ValidAsCString(str)) {
- if (pf_invalid) {
- *pf_invalid = true;
- }
+ *pf_invalid = true;
return {};
}
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str(), pf_invalid);
@@ -245,7 +243,7 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
++p;
}
valid = valid && (p - e) % 8 == 0 && p - q < 8;
- if (pf_invalid) *pf_invalid = !valid;
+ *pf_invalid = !valid;
return ret;
}
@@ -253,9 +251,7 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
std::string DecodeBase32(const std::string& str, bool* pf_invalid)
{
if (!ValidAsCString(str)) {
- if (pf_invalid) {
- *pf_invalid = true;
- }
+ *pf_invalid = true;
return {};
}
std::vector<unsigned char> vchRet = DecodeBase32(str.c_str(), pf_invalid);