Skip to content

Commit

Permalink
Bugfix: prioritisetransaction: Do some basic sanity checking on txid
Browse files Browse the repository at this point in the history
Besides giving a nicer error, this also prevents logging arbitrary data (which could have been used to exploit log readers) into debug.log
  • Loading branch information
luke-jr committed Dec 17, 2014
1 parent 41cced2 commit 7f71813
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern CScript ParseScript(std::string s);
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
extern bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
extern uint256 ParseHashUV(const UniValue& v, const std::string& strName);
extern uint256 ParseHashStr(const std::string&, const std::string& strName);
extern std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);

// core_write.cpp
Expand Down
5 changes: 5 additions & 0 deletions src/core_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ uint256 ParseHashUV(const UniValue& v, const string& strName)
string strHex;
if (v.isStr())
strHex = v.getValStr();
return ParseHashStr(strHex, strName); // Note: ParseHashStr("") throws a runtime_error
}

uint256 ParseHashStr(const std::string& strHex, const std::string& strName)
{
if (!IsHex(strHex)) // Note: IsHex("") is false
throw runtime_error(strName+" must be hexadecimal string (not '"+strHex+"')");

Expand Down
3 changes: 1 addition & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ Value prioritisetransaction(const Array& params, bool fHelp)
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
);

uint256 hash;
hash.SetHex(params[0].get_str());
uint256 hash = ParseHashStr(params[0].get_str(), "txid");

CAmount nAmount = params[2].get_int64();

Expand Down

0 comments on commit 7f71813

Please sign in to comment.