mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-16 09:13:50 +00:00
fix: UB in mouse button polling, null deref in BigNum formatting
- input: fix undefined behavior in SDL mouse button loop — SDL_BUTTON(0) computes (1 << -1) which is UB. Start loop at 1 since SDL button indices are 1-based (SDL_BUTTON_LEFT=1, RIGHT=3, MIDDLE=2) - big_num: guard BN_bn2hex/BN_bn2dec against nullptr return on OpenSSL allocation failure — previously constructed std::string from nullptr which is undefined behavior
This commit is contained in:
parent
fe7912b5fa
commit
af604cc442
2 changed files with 7 additions and 1 deletions
|
|
@ -136,6 +136,8 @@ std::vector<uint8_t> BigNum::toArray(bool littleEndian, int minSize) const {
|
|||
|
||||
std::string BigNum::toHex() const {
|
||||
char* hex = BN_bn2hex(bn);
|
||||
// BN_bn2hex returns nullptr on allocation failure
|
||||
if (!hex) return "(null)";
|
||||
std::string result(hex);
|
||||
OPENSSL_free(hex);
|
||||
return result;
|
||||
|
|
@ -143,6 +145,7 @@ std::string BigNum::toHex() const {
|
|||
|
||||
std::string BigNum::toDecimal() const {
|
||||
char* dec = BN_bn2dec(bn);
|
||||
if (!dec) return "(null)";
|
||||
std::string result(dec);
|
||||
OPENSSL_free(dec);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ void Input::update() {
|
|||
Uint32 mouseState = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
mousePosition = glm::vec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
|
||||
|
||||
for (int i = 0; i < NUM_MOUSE_BUTTONS; ++i) {
|
||||
// SDL_BUTTON(x) is defined as (1 << (x-1)), so button indices are 1-based.
|
||||
// SDL_BUTTON(0) is undefined behavior (negative shift). Start at 1.
|
||||
currentMouseState[0] = false;
|
||||
for (int i = 1; i < NUM_MOUSE_BUTTONS; ++i) {
|
||||
currentMouseState[i] = (mouseState & SDL_BUTTON(i)) != 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue