Skip to content

CurrentTimeService: Initialize the whole current-time response - #2459

Open
JoeStrout wants to merge 1 commit into
InfiniTimeOrg:mainfrom
JoeStrout:fix-cts-uninitialised-read
Open

CurrentTimeService: Initialize the whole current-time response#2459
JoeStrout wants to merge 1 commit into
InfiniTimeOrg:mainfrom
JoeStrout:fix-cts-uninitialised-read

Conversation

@JoeStrout

Copy link
Copy Markdown

The read handler for the Current Time characteristic fills in seven of the nine fields of CtsCurrentTimeData. dayofweek and reason are never assigned, and the struct is a plain local, so those two bytes go out over the air as whatever was on the stack.

dayofweek is the one that matters: it is a defined part of the characteristic, and a client reading the time gets a random day. This PR assigns it from DateTime::DayOfWeek(), whose Days enum already matches the GATT encoding exactly (Unknown = 0, Monday = 1 ... Sunday = 7), so it casts directly like Month() on the line above. reason is an adjust-reason bit field with no bits to report here, so it is set to 0.

The read handler for the Current Time characteristic fills in seven of
the nine fields of CtsCurrentTimeData. dayofweek and reason are never
assigned, and the struct is a plain local, so those two bytes go out over
the air as whatever was on the stack.

dayofweek is the one that matters: it is a defined part of the
characteristic, and a client reading the time gets a random day. Assign it
from DateTime::DayOfWeek(), whose Days enum already matches the GATT
encoding exactly (Unknown = 0, Monday = 1 ... Sunday = 7), so it casts
directly like Month() on the line above. reason is an adjust-reason bit
field with no bits to report here, so it is set to 0.
@github-actions

Copy link
Copy Markdown

Build size and comparison to main:

Section Size Difference
text 385248B 16B
data 944B 0B
bss 22640B 0B

Run in InfiniEmu

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.

1 participant