-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Improve memory store safety by avoiding unaligned stores
- Loading branch information
Showing
3 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace safetyhook { | ||
template <typename T> constexpr void store(uint8_t* address, const T& value) { | ||
const auto data = reinterpret_cast<const uint8_t*>(&value); | ||
|
||
// Write each byte out individually to avoid undefined behavior. | ||
for (size_t i = 0; i < sizeof(T); ++i) { | ||
address[i] = data[i]; | ||
} | ||
} | ||
} // namespace safetyhook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters