Skip to content

Commit

Permalink
Wallet: Sanitise -wallet parameter
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#8775
Rebased-From: d678771
  • Loading branch information
luke-jr committed Mar 3, 2017
1 parent 94964a3 commit 6689b85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/utilstrencodings.cpp
Expand Up @@ -19,7 +19,8 @@ static const string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
static const string SAFE_CHARS[] =
{
CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
CHARS_ALPHA_NUM + " .,;-_?@" // SAFE_CHARS_UA_COMMENT
CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
};

string SanitizeString(const string& str, int rule)
Expand Down
3 changes: 2 additions & 1 deletion src/utilstrencodings.h
Expand Up @@ -26,7 +26,8 @@
enum SafeChars
{
SAFE_CHARS_DEFAULT, //!< The full set of allowed chars
SAFE_CHARS_UA_COMMENT //!< BIP-0014 subset
SAFE_CHARS_UA_COMMENT, //!< BIP-0014 subset
SAFE_CHARS_FILENAME, //!< Chars allowed in filenames
};

/**
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/wallet.cpp
Expand Up @@ -3765,6 +3765,12 @@ bool CWallet::InitLoadWallet()

std::string walletFile = GetArg("-wallet", DEFAULT_WALLET_DAT);

if (walletFile.find_first_of("/\\") != std::string::npos) {
return InitError(_("-wallet parameter must only specify a filename (not a path)"));
} else if (SanitizeString(walletFile, SAFE_CHARS_FILENAME) != walletFile) {
return InitError(_("Invalid characters in -wallet filename"));
}

CWallet * const pwallet = CreateWalletFromFile(walletFile);
if (!pwallet) {
return false;
Expand Down

0 comments on commit 6689b85

Please sign in to comment.