Skip to content

Commit f921cfb

Browse files
authored
MaybeReenterWithoutASLR(): be more cautious about argument types (#1983)
It seems, on android the argument is narrower than on linux. Let's try to support that while not introducing any explicit lossy casts. Fixes #1982
1 parent afd9c34 commit f921cfb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/benchmark.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,12 @@ int InitializeStreams() {
815815
return 0;
816816
}
817817

818+
template <typename T>
819+
std::make_unsigned_t<T> get_as_unsigned(T v) {
820+
using UnsignedT = std::make_unsigned_t<T>;
821+
return static_cast<UnsignedT>(v);
822+
}
823+
818824
} // end namespace internal
819825

820826
void MaybeReenterWithoutASLR(int /*argc*/, char** argv) {
@@ -829,11 +835,12 @@ void MaybeReenterWithoutASLR(int /*argc*/, char** argv) {
829835
if (curr_personality == -1) return;
830836

831837
// If ASLR is already disabled, we have nothing more to do.
832-
if (curr_personality & ADDR_NO_RANDOMIZE) return;
838+
if (internal::get_as_unsigned(curr_personality) & ADDR_NO_RANDOMIZE) return;
833839

834840
// Try to change the personality to disable ASLR.
835-
const auto prev_personality = personality(
836-
static_cast<unsigned long>(curr_personality) | ADDR_NO_RANDOMIZE);
841+
const auto proposed_personality =
842+
internal::get_as_unsigned(curr_personality) | ADDR_NO_RANDOMIZE;
843+
const auto prev_personality = personality(proposed_personality);
837844

838845
// Have we failed to change the personality? That may happen.
839846
if (prev_personality == -1) return;

0 commit comments

Comments
 (0)