Skip to content

Commit 30ac768

Browse files
committed
Fix subscript[0] potential bugs in key.cpp
1 parent 4b1c0f2 commit 30ac768

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/key.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CPrivKey CKey::GetPrivKey() const {
138138
size_t privkeylen;
139139
privkey.resize(279);
140140
privkeylen = 279;
141-
ret = ec_privkey_export_der(secp256k1_context_sign, (unsigned char*)&privkey[0], &privkeylen, begin(), fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
141+
ret = ec_privkey_export_der(secp256k1_context_sign, (unsigned char*) privkey.data(), &privkeylen, begin(), fCompressed ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED);
142142
assert(ret);
143143
privkey.resize(privkeylen);
144144
return privkey;
@@ -167,7 +167,7 @@ bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_
167167
secp256k1_ecdsa_signature sig;
168168
int ret = secp256k1_ecdsa_sign(secp256k1_context_sign, &sig, hash.begin(), begin(), secp256k1_nonce_function_rfc6979, test_case ? extra_entropy : NULL);
169169
assert(ret);
170-
secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, (unsigned char*)&vchSig[0], &nSigLen, &sig);
170+
secp256k1_ecdsa_signature_serialize_der(secp256k1_context_sign, (unsigned char*)vchSig.data(), &nSigLen, &sig);
171171
vchSig.resize(nSigLen);
172172
return true;
173173
}
@@ -202,7 +202,7 @@ bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig)
202202
}
203203

204204
bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
205-
if (!ec_privkey_import_der(secp256k1_context_sign, (unsigned char*)begin(), &privkey[0], privkey.size()))
205+
if (!ec_privkey_import_der(secp256k1_context_sign, (unsigned char*)begin(), privkey.data(), privkey.size()))
206206
return false;
207207
fCompressed = vchPubKey.IsCompressed();
208208
fValid = true;
@@ -245,8 +245,8 @@ void CExtKey::SetMaster(const unsigned char *seed, unsigned int nSeedLen) {
245245
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
246246
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
247247
CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
248-
key.Set(&vout[0], &vout[32], true);
249-
memcpy(chaincode.begin(), &vout[32], 32);
248+
key.Set(vout.data(), vout.data() + 32, true);
249+
memcpy(chaincode.begin(), vout.data() + 32, 32);
250250
nDepth = 0;
251251
nChild = 0;
252252
memset(vchFingerprint, 0, sizeof(vchFingerprint));

0 commit comments

Comments
 (0)