Skip to content

Conversation

@fasuizu-br
Copy link

Summary

get_unix_time_by_addr() performed (raw_secs - SNTP_TIME_OFFSET) as i64 where both operands are u32. If raw_secs < SNTP_TIME_OFFSET (e.g. dates before 1970 in NTP epoch), this causes a u32 underflow panic in debug mode or wraps silently in release mode. Fixed by casting both operands to i64 before subtraction.

Closes #10

Test plan

  • cargo check passes
  • cargo test — all tests pass

Cast raw_secs and SNTP_TIME_OFFSET to i64 before subtraction to
prevent u32 underflow panic when raw_secs < SNTP_TIME_OFFSET
(e.g. dates before 1970 in NTP epoch).

Closes risoflora#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: u32 underflow in Unix timestamp calculation

1 participant