Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lua getNumber overflow #1944

Merged
merged 4 commits into from
Nov 30, 2023
Merged

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Nov 30, 2023

Converting Lua numbers to unsigned integer types in C++ can be problematic due to Lua's lua_tonumber function defaulting to -1 when no explicit integer is defined. This poses an overflow risk when casting to unsigned types like uint32_t or uint16_t in C++, as negative values translate to large positive numbers.

This pull request addresses the issue by implementing a check in the Lua-to-C++ conversion function. If lua_tonumber returns a negative value, we adjust the value to 0 for unsigned types. This ensures safe and accurate conversion of Lua values to C++ unsigned integers, avoiding unexpected overflow and maintaining data integrity.

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@dudantas dudantas merged commit a1510a8 into main Nov 30, 2023
36 checks passed
@dudantas dudantas deleted the dudantas/fix-lua-get-number-overflow branch November 30, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants