Bug 1616938 - Fix some test issues in TestNetworkLinkIdHashingWindows r=mayhemer

TestNetworkLinkIdHashingWindows has two issues that, frighteningly, cancelled each other out under most conditions.

First is that the `sscanf` format string uses curly braces when the test data does not have braces.

Second is that the order of `nwGUIDS` does not match the sorting behavior of `nsNotifyAddrListener::HashSortedNetworkIds`.

What ended up happening was that the sscanf failed, and left the entire GUID uninitialized. Then we used that uninitialized data over and over in `nwGUIDS` so the order didn't matter. However, under AddressSanitizer, the failure became evident, because (I think, haven't verified) that ASan's instrumentation messes with the contents of the stack between the four GUID parses, so we no longer use the same uninitialized data four times. And for bonus fun, this wasn't noticed in CI because we don't (yet) run ASan on GTests for Windows.

Debugging this was... quite an adventure.

Differential Revision: https://phabricator.services.mozilla.com/D63532

--HG--
extra : moz-landing-system : lando
This commit is contained in:
David Major 2020-02-25 13:41:02 +00:00
Родитель cb8e00ff3f
Коммит 0e91db76c5
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -9,7 +9,7 @@ using namespace mozilla;
GUID StringToGuid(const std::string& str) {
GUID guid;
sscanf(str.c_str(),
"{%8lx-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx}",
"%8lx-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
&guid.Data1, &guid.Data2, &guid.Data3, &guid.Data4[0], &guid.Data4[1],
&guid.Data4[2], &guid.Data4[3], &guid.Data4[4], &guid.Data4[5],
&guid.Data4[6], &guid.Data4[7]);
@ -47,10 +47,10 @@ TEST(TestNetworkLinkIdHashingWindows, Multiple)
SHA1Sum::Hash expected_digest;
std::vector<GUID> nwGUIDS;
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000004"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000003"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000002"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000001"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000002"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000003"));
nwGUIDS.push_back(StringToGuid("00000000-0000-0000-0000-000000000004"));
for (const auto& guid : nwGUIDS) {
expected_sha1.update(&guid, sizeof(GUID));