Skip to content

Commit

Permalink
fix: DecodeBase64 changes in dash code
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaPastaPasta committed Jan 12, 2025
1 parent b6122ea commit 5271cfa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
11 changes: 5 additions & 6 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,11 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
return false;

std::string strUserPass64 = TrimString(strAuth.substr(6));
bool invalid;
std::string strUserPass = DecodeBase64(strUserPass64, &invalid);
if (invalid) return false;

if (strUserPass.find(':') == std::string::npos) return false;
const std::string username{strUserPass.substr(0, strUserPass.find(':'))};
auto opt_strUserPass = DecodeBase64(strUserPass64);
if (!opt_strUserPass.has_value()) return false;
auto it = std::find(opt_strUserPass->begin(), opt_strUserPass->end(), ':');
if (it == opt_strUserPass->end()) return false;
const std::string username = std::string(opt_strUserPass->begin(), it);
return find(g_external_usernames.begin(), g_external_usernames.end(), username) != g_external_usernames.end();
}();

Expand Down
12 changes: 6 additions & 6 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,9 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
} else if (err != SigningResult::OK){
throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err));
}
bool invalid = false;
ptx.vchSig = DecodeBase64(signed_payload.c_str(), &invalid);
if (invalid) throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to decode base64 ready signature for protx");
auto opt_vchSig = DecodeBase64(signed_payload);
if (!opt_vchSig.has_value()) throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to decode base64 ready signature for protx");
ptx.vchSig = opt_vchSig.value();
} // cs_wallet
SetTxPayload(tx, ptx);
return SignAndSendSpecialTx(request, chain_helper, chainman, tx, fSubmit);
Expand Down Expand Up @@ -877,11 +877,11 @@ static RPCHelpMan protx_register_submit()
throw JSONRPCError(RPC_INVALID_PARAMETER, "payload signature not empty");
}

bool decode_fail{false};
ptx.vchSig = DecodeBase64(request.params[1].get_str().c_str(), &decode_fail);
if (decode_fail) {
auto opt_vchSig= DecodeBase64(request.params[1].get_str());
if (!opt_vchSig.has_value()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "malformed base64 encoding");
}
ptx.vchSig = opt_vchSig.value();

SetTxPayload(tx, ptx);
return SignAndSendSpecialTx(request, chain_helper, chainman, tx);
Expand Down
14 changes: 6 additions & 8 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,10 @@ static bool SignVote(const CWallet& wallet, const CKeyID& keyID, CGovernanceVote
LogPrintf("SignVote failed due to: %s\n", SigningResultString(err));
return false;
}
bool failed = true;
const auto decoded = DecodeBase64(signature, &failed);
CHECK_NONFATAL(!failed); // DecodeBase64 should not fail
const auto opt_decoded = DecodeBase64(signature);
CHECK_NONFATAL(opt_decoded.has_value()); // DecodeBase64 should not fail

vote.SetSignature(std::vector<unsigned char>(decoded.data(), decoded.data() + decoded.size()));
vote.SetSignature(std::vector<unsigned char>(opt_decoded->data(), opt_decoded->data() + opt_decoded->size()));
return true;
}

Expand Down Expand Up @@ -959,10 +958,9 @@ static RPCHelpMan voteraw()

int64_t nTime = request.params[5].get_int64();
std::string strSig = request.params[6].get_str();
bool fInvalid = false;
std::vector<unsigned char> vchSig = DecodeBase64(strSig.c_str(), &fInvalid);
auto opt_vchSig = DecodeBase64(strSig);

if (fInvalid) {
if (!opt_vchSig.has_value()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
}

Expand All @@ -975,7 +973,7 @@ static RPCHelpMan voteraw()

CGovernanceVote vote(outpoint, hashGovObj, eVoteSignal, eVoteOutcome);
vote.SetTime(nTime);
vote.SetSignature(vchSig);
vote.SetSignature(opt_vchSig.value());

bool onlyVotingKeyAllowed = govObjType == GovernanceObject::PROPOSAL && vote.GetSignal() == VOTE_SIGNAL_FUNDING;

Expand Down
7 changes: 3 additions & 4 deletions src/stacktraces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,12 @@ std::string GetCrashInfoStrFromSerializedStr(const std::string& ciStr)
{
static uint64_t basePtr = GetBaseAddress();

bool dataInvalid = false;
auto buf = DecodeBase32(ciStr.c_str(), &dataInvalid);
if (buf.empty() || dataInvalid) {
auto opt_buf = DecodeBase32(ciStr.c_str());
if (!opt_buf.has_value() || opt_buf->empty()) {
return "Error while deserializing crash info";
}

CDataStream ds(buf, SER_DISK, 0);
CDataStream ds(*opt_buf, SER_DISK, 0);

crash_info_header hdr;
try {
Expand Down

0 comments on commit 5271cfa

Please sign in to comment.