Skip to content

Commit

Permalink
Bug 1578626 - Remove undefined nullptr decrement, r=keeler
Browse files Browse the repository at this point in the history
Summary:
This uses uintptr_t to avoid the worst.  It still looks terrible and might trip
static analysis warnings, but the reinterpret_cast should hide that.

This assumes that sizeof(uintptr_t) == sizeof(void*), so I've added an assertion
so that we'll at least fail the test on those systems.  (We could use
GTEST_SKIP instead, but we don't have that in the version of gtest that we use.)

Reviewers: keeler

Tags: #secure-revision

Bug #: 1578626

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

--HG--
extra : rebase_source : a5719e3e11fbed46661e9bf22c5e7215da702f6b
  • Loading branch information
martinthomson committed Sep 4, 2019
1 parent 574e8d2 commit 1d2fd6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gtests/mozpkix_gtest/pkixder_input_tests.cpp
Expand Up @@ -191,8 +191,10 @@ TEST_F(pkixder_input_tests, ReadByteWrapAroundPointer)
// a null pointer is undefined behavior according to the C++ language spec.,
// but this should catch the problem on at least some compilers, if not all of
// them.
const uint8_t* der = nullptr;
--der;
uintptr_t derint = -1;
auto der = reinterpret_cast<const uint8_t*>(derint);
ASSERT_EQ(sizeof(der), sizeof(derint))
<< "underflow of pointer might not work";
Input buf;
ASSERT_EQ(Success, buf.Init(der, 0));
Reader input(buf);
Expand Down

0 comments on commit 1d2fd6c

Please sign in to comment.