Skip to content

Conversation

JeremyRubin
Copy link
Contributor

@JeremyRubin JeremyRubin commented Feb 19, 2017

This PR fixes up a couple places where the codebase has semi-risky uses of 0 subscript. I don't think any of these are actively bugs, but some of them are unsafe (or unexpected-errors) for unsanitized inputs (such as in addrdb or key.cpp).

This also allows us to eliminate some bounds checks, so I guess this is a net-negative patch. I don't think any of those bounds checks are performance sensitive, but worth double checking in review.

p.s. I also fix some confusing code in murmurhash (with non obvious offset-math) as it took me a little bit to see that it was correct, could separate that out if desired.

@@ -229,7 +229,7 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
string DecodeBase64(const string& str)
{
vector<unsigned char> vchRet = DecodeBase64(str.c_str());
return (vchRet.size() == 0) ? string() : string((const char*)vchRet.data(), vchRet.size());
return string((const char*)vchRet.data(), vchRet.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string maybe?

@JeremyRubin
Copy link
Contributor Author

Sorry for the bit of line noise, there was some UB when I removed some of the branches (memset/memcpy/read/write 0 bytes on nullptr/invalid ptr) that was causing one of the builds (with more aggressive runtime checks) to fail. I added them back in and all seems well now.

@laanwj
Copy link
Member

laanwj commented Feb 20, 2017

Whoa, good catch.

I'm shocked that &vch[0] use was still so rampant in the code. We'd introduced begin_ptr with the intention to replace those, and phased even that out again with C++11 .data().

Anyhow, concept ACK.

src/serialize.h Outdated
@@ -571,7 +571,7 @@ void Serialize_impl(Stream& os, const prevector<N, T>& v, const unsigned char&)
{
WriteCompactSize(os, v.size());
if (!v.empty())
os.write((char*)&v[0], v.size() * sizeof(T));
os.write((char*) v.data(), v.size() * sizeof(T));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we're casting to (char*) here iso (const char*), even though these are write operations and the type passed in is const.

There's a couple more of these. Though seems out of scope to fix in this pull.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that seems obviously incorrect, but I think I understand why it was done (or at least have a theory). Because the methods are all generic w.r.t. the stream type, they probably are made to work with some arbitrary stream that can't accept a const char *. Hopefully not the case anymore...

Anyways, probably best to fix those up separately as you suggest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but it would be wrong for a stream write to take a char* i.s.o. const char*, so fixing those just means the const-correctness spreads.

@JeremyRubin
Copy link
Contributor Author

There are still a few more places that were trickier/not possible to correct (where the type passed in is templated, such that it would be a pointer or a vector).

I also didn't fix anything in subdirectories, because I felt this PR was getting a bit large already, and there are a few you can still grep for pretty easily there:

❯ grep '\&v[A-z0-9_]*\[0\]' */*.cpp | nl
    1	qt/signverifymessagedialog.cpp:    ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size())));
    2	rpc/misc.cpp:    return EncodeBase64(&vchSig[0], vchSig.size());
    3	script/ismine.cpp:        CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(hash.begin());
    4	script/sigcache.cpp:        CSHA256().Write(nonce.begin(), 32).Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(&vchSig[0], vchSig.size()).Finalize(entry.begin());
    5	script/sign.cpp:        CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin());
    6	script/standard.cpp:            CHash160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160);
    7	test/getarg_tests.cpp:    ParseParameters(vecChar.size(), &vecChar[0]);
    8	test/skiplist_tests.cpp:        BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]);
    9	wallet/crypter.cpp:    size_t nLen = enc.Encrypt(&vchPlaintext[0], vchPlaintext.size(), &vchCiphertext[0]);
   10	wallet/crypter.cpp:    nLen = dec.Decrypt(&vchCiphertext[0], vchCiphertext.size(), &vchPlaintext[0]);
   11	wallet/rpcwallet.cpp:    return EncodeBase64(&vchSig[0], vchSig.size());
   12	wallet/wallet.cpp:    GetStrongRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);

(there are a lot more worth checking if you don't use the hungarian notation v prefix as a filter)

src/serialize.h Outdated
@@ -549,7 +549,7 @@ void Serialize(Stream& os, const std::basic_string<C>& str)
{
WriteCompactSize(os, str.size());
if (!str.empty())
os.write((char*)&str[0], str.size() * sizeof(str[0]));
os.write((char*) str.data(), str.size() * sizeof(typename std::basic_string<C>::value_type));
Copy link
Contributor

@TheBlueMatt TheBlueMatt Feb 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this is equivalent to sizeof(C) (std::basic_string<C>::value_type is std::basic_string<C, std::char_traits<C>>::value_type which is std::char_traits<C>::char_type, which is C).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheBlueMatt is right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was aware :) I felt that the version I chose was more similar to the existing code (the size of whatever str[0] returns), but if everyone is comfortable with sizeof(C) I can change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed

@@ -229,7 +229,7 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
string DecodeBase64(const string& str)
{
vector<unsigned char> vchRet = DecodeBase64(str.c_str());
return (vchRet.size() == 0) ? string() : string((const char*)&vchRet[0], vchRet.size());
return std::string((const char*)vchRet.data(), vchRet.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, based on cppreference I cant tell if this is well-defined with vchRet.size() == 0 or not.

Copy link
Contributor

@dcousens dcousens Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding (it doesn't seem ambiguous, but, it certainly isn't definitive), a len of 0 is well-defined, and simply an empty string. Aka, equivalent to std::string().
I don't have a definitive statement from the reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a string with size 0 is well-defined. Calling .data() on a string of size 0 is also defined. This should be ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is whether calling std::string(garbage_pointer, 0) is well-defined. I can't tell from what cppreference.com says (The behavior is undefined if s does not point at an array of at least count elements of CharT, including the case when s is a null pointer.).

As an alternative, what about std::string(vchRet.begin(), vchRet.end())?

Copy link
Member

@laanwj laanwj Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that as: If the count is 0, it always points at least 0 elements, thus "point at an array of at least count elements of CharT" is always satisfied.

Alternatively: if count is 0 it would be wrong to dereference the pointer's address at all.

Copy link
Member

@sipa sipa Feb 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that "a pointer to an array of 0 elements of type T" can be any pointer. I think it's extremely unlikely to matter, and that every C++ std library effectively is implemented in a way that makes the constructor, when invoked with (pointer, 0) effectively ignore pointer, however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean when cppreference is ambiguous thats probably a good sign that trying to parse a wiki is going to get your an incorrect result...best to go to the standard if in doubt in that case. :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is can be a garbage pointer. vector.data() is guaranteed to return a valid range (even when empty), which I think would require that it have proper alignment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be complete: this is not the same as std::string(vchRet.begin(), vchRet.end()) in the general case. When creating an iterator range, if the type of vch is different from the type of string, a per-element cast will happen. So string.size() will be vch.size(). Usual issues with casting between signed and unsigned apply.

std::string((const char*)vchRet.data(), vchRet.size()) however just return the memory area with all the elements of the vector as a string. So string.size() will be vch.size()*sizeof(vch::value_type). It is likely also more efficient.

@gmaxwell
Copy link
Contributor

Concept ACK.

@practicalswift
Copy link
Contributor

Concept ACK! 👍

@JeremyRubin JeremyRubin force-pushed the fix-subscript-0 branch 2 times, most recently from 7a3a263 to 337e562 Compare March 27, 2017 17:17
@JeremyRubin
Copy link
Contributor Author

Rebased.

src/hash.cpp Outdated
const uint8_t* tail = (const uint8_t*)(&vDataToHash[0] + nblocks * 4);
//----------
// tail
const uint8_t* tail = (const uint8_t*)(vDataToHash.data() + nblocks * 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit: "Cleanup (safe, it was checked) 0-subscript in MurmurHash3"

Could you drop this (const uint8_t*) cast here? It shouldn't be needed since we already call vDataToHash.data() with no cast above on line 27.

@@ -227,8 +227,8 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)

std::string DecodeBase64(const std::string& str)
{
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str());
return (vchRet.size() == 0) ? std::string() : std::string((const char*)&vchRet[0], vchRet.size());
vector<unsigned char> vchRet = DecodeBase64(str.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Fix 0-subscript in utilstrencodings.cpp"

Should put back std:: prefixes.

@@ -414,8 +414,13 @@ std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)

std::string DecodeBase32(const std::string& str)
{
<<<<<<< 1f0401c11315b5090cfe2b37f6338205e2984372
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Fix 0-subscript in utilstrencodings.cpp"

Bad merge here.

src/streams.h Outdated
@@ -385,7 +385,7 @@ class CDataStream
{
// Special case: stream << stream concatenates like stream += stream
if (!vch.empty())
s.write((char*)&vch[0], vch.size() * sizeof(vch[0]));
s.write((char*) vch.data(), vch.size() * sizeof(typename decltype(vch)::value_type));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Fix subscript-0 in streams.h"

It would seem more direct (and shorter) to write sizeof(*vch.data()).

@@ -227,8 +227,8 @@ std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)

std::string DecodeBase64(const std::string& str)
{
vector<unsigned char> vchRet = DecodeBase64(str.c_str());
return (vchRet.size() == 0) ? string() : string((const char*)vchRet.data(), vchRet.size());
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Remove uneccessary branches in utilstrencodings string constructors."

Some of the changes in this commit should be squashed into previous commit "In commit "Fix 0-subscript in utilstrencodings.cpp."

Also missing an n in unnecessary.

@JeremyRubin JeremyRubin force-pushed the fix-subscript-0 branch 2 times, most recently from c4d844a to 275caff Compare March 28, 2017 15:38
@JeremyRubin
Copy link
Contributor Author

@ryanofsky feedback addressed.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 275caff431cea65aa77d6a3035597b4b2b9b0052. Only changes since previous review (69fd8ab0a6543dace4b080166b21b2aafdd2c0a9) were addressing feedback and combining / rearranging some of the commits.

@laanwj
Copy link
Member

laanwj commented Jun 26, 2017

Needs rebase again (sorry).

jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Jun 13, 2019
…) instead.

Summary:
30ac7688e Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2e2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b5a Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd98 Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1e0 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e55f Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856ebed Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d95265 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf16 Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119e6 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710bd2 Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3e2 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362

Backport of Core PR 9693
bitcoin/bitcoin#9804

Test Plan:
make check
test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: markblundeberg

Differential Revision: https://reviews.bitcoinabc.org/D2964
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Jun 13, 2019
…) instead.

Summary:
30ac7688e Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2e2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b5a Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd98 Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1e0 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e55f Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856ebed Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d95265 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf16 Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119e6 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710bd2 Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3e2 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362

Backport of Core PR 9693
bitcoin/bitcoin#9804

Test Plan:
make check
test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: markblundeberg

Differential Revision: https://reviews.bitcoinabc.org/D2964
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 6, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 6, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 8, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 9, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 11, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 13, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 17, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 18, 2019
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
schancel pushed a commit to givelotus/lotusd that referenced this pull request Jul 18, 2019
Summary:
592404f03 Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin/bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656

Backport of Core PR10793
bitcoin/bitcoin#10793

Test Plan:
  make check
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 23, 2019
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 21, 2019
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 4, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 4, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 10, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 10, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 10, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 12, 2020
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
….data()) instead.

30ac768 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
4b1c0f2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
e19db7b Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
bc2e7fd Fix subscript[0] in streams.h (Jeremy Rubin)
4cac0d1 Fix subscript[0] in validation.cpp (Jeremy Rubin)
ac658e5 Fix subscript[0] in torcontrol (Jeremy Rubin)
b6856eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
361d952 Fix subscript[0] in base58.cpp (Jeremy Rubin)
6896dbf Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
96f2119 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
500710b Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin)
e0451e3 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)

Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
zkbot added a commit to zcash/zcash that referenced this pull request Sep 29, 2020
Locked memory manager

Add a pool for locked memory chunks, replacing `LockedPageManager`.

Cherry-picked from the following upstream PRs:
- bitcoin/bitcoin#8321
- bitcoin/bitcoin#8753
- bitcoin/bitcoin#9063
- bitcoin/bitcoin#9070
- bitcoin/bitcoin#11385
- bitcoin/bitcoin#12048
  - Excludes change to benchmark.
- bitcoin/bitcoin#15117
- bitcoin/bitcoin#16161
  - Excludes Travis CI changes.
  - Includes change from bitcoin/bitcoin#13163
- bitcoin/bitcoin#15600
- bitcoin/bitcoin#18443
- Assorted small changes from:
  - bitcoin/bitcoin#9233
  - bitcoin/bitcoin#10483
  - bitcoin/bitcoin#10645
  - bitcoin/bitcoin#10969
  - bitcoin/bitcoin#11351
- bitcoin/bitcoin#19111
  - Excludes change to `src/rpc/server.cpp`
- bitcoin/bitcoin#9804
  - Only the commit for `src/key.cpp`
- bitcoin/bitcoin#9598
maflcko pushed a commit that referenced this pull request May 5, 2021
fac30ee refactor: Replace &foo[0] with foo.data() (MarcoFalke)
faece47 refactor: Avoid &foo[0] on C-Style arrays (MarcoFalke)
face961 refactor: Use only one temporary buffer in CreateObfuscateKey (MarcoFalke)
fa05ddd refactor: Use CPubKey vector constructor where possible (MarcoFalke)
fabb6df script: Replace address-of idiom with vector data() method (Guido Vranken)

Pull request description:

  The main theme of this refactor is to replace `&foo[0]` with `foo.data()`.

  The first commit is taken from #21781 with the rationale:

  * In CSignatureCache::ComputeEntryECDSA, change the way a vector pointer is resolved to prevent invoking undefined behavior if the vector is empty.

  The other commits aim to remove all `&foo[0]`, where `foo` is any kind of byte representation. The rationale:

  * Sometimes alternative code without any raw data pointers is easier to read (refer to the respective commit message for details)
  * If the raw data pointer is needed, `foo.data()` should be preferred, as pointed out in the developer notes. This addresses the instances that have been missed in commit 592404f, and #9804

ACKs for top commit:
  laanwj:
    Code review ACK fac30ee
  practicalswift:
    cr ACK fac30ee: patch looks correct
  promag:
    Code review ACK fac30ee.

Tree-SHA512: e7e73146edbc78911a8e8c728b0a1c6b0ed9a88a008e650aa5dbffe72425bd42c76df70199a9cf7e02637448d7593e0eac52fd0f91f59240283e1390ee21bfa5
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jun 9, 2021
fcdf87a Populate services in GetLocalAddress (Alex Morcos)
a0a079f Return early in IsBanned. (Gregory Maxwell)
7772138 Remove redundant nullptr checks before deallocation (practicalswift)
5390862 net: remove unimplemented functions. (furszy)
74d0482 Limit setAskFor and retire requested entries only when a getdata returns. (Gregory Maxwell)
3b3bf63 prevent peer flooding request queue for an inv (kazcw)
c814967 Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin)
8e2e79e Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin)
25a16b3 Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin)
df0584e Fix subscript[0] in streams.h (Jeremy Rubin)
b7e64a5 Fix subscript[0] in validation.cpp (Jeremy Rubin)
2f7b73b Fix subscript[0] in torcontrol (Jeremy Rubin)
3b883eb Fix subscript[0] in netaddress.cpp (Jeremy Rubin)
e5f5401 Fix subscript[0] in base58.cpp (Jeremy Rubin)
7d4ec87 Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin)
5e14f54 Fix subscript[0] in compressor.cpp (Jeremy Rubin)
48a622d Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin)
af4cba3 net: use an internal address for fixed seeds (Cory Fields)
36368c5 net: switch to dummy internal ip for dns seed source (Cory Fields)
8f31295 net: do not allow resolving to an internal address (Cory Fields)
8ba3a40 net: add an internal subnet for representing unresolved hostnames (Cory Fields)
c60b875 fix uninitialized read when stringifying an addrLocal (Kaz Wesley)
3d36540 add test demonstrating addrLocal UB (Kaz Wesley)

Pull request description:

  Grouped some net updates (plus a miscellaneous one) coming from upstream.
  Part of another deep rabbit hole that i'm doing in parallel of the tier two work.

  PRs List:
  * bitcoin#7079.
  * bitcoin#9804.
  * bitcoin#10424
  * bitcoin#10446.
  * bitcoin#10564.
  * bitcoin#14728.

ACKs for top commit:
  random-zebra:
    Code ACK fcdf87a

Tree-SHA512: ee81c834641aa6fdb9ca4396657457358a4b32f7862d60716e914dcfc2d355970937bd0fb4e164faaa0f4ea26d263ca8a2af4d8d5d6615b2db5bf89ec70d15f3
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 28, 2021
592404f Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider)

Pull request description:

  This just continues the work of bitcoin#9804

  Modifies a lot of `&vector[]`'s to `vector.data()`'s across all the files including tests, just the stuff that 9804 missed

Tree-SHA512: dd1a9dffb999dea4fba78dcc91fe02f90250db86f5c74948e1ff3e8b4036b2154b600555eaa04dece5368920aae3513bc36425dc96e4319ca1041b0928a6b656
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants