Skip to content

FSService: Initialise WriteResponse::status on all paths - #2457

Closed
JoeStrout wants to merge 1 commit into
InfiniTimeOrg:mainfrom
JoeStrout:fix-fsservice-write-status
Closed

JoeStrout wants to merge 1 commit into
InfiniTimeOrg:mainfrom
JoeStrout:fix-fsservice-write-status

Conversation

@JoeStrout

Copy link
Copy Markdown
Contributor

WriteResponse has no default member initialisers and both write handlers assigned status on only one branch, so the other returned uninitialised stack memory to the client over BLE:

  • commands::WRITE assigned status only on success, so a failed FileOpen reported garbage. (The ternary was also dead code, as res is known to be 0 inside that branch.)
  • commands::WRITE_DATA assigned status only on failure, so every successful chunk reported garbage, which readily looks like a negative LittleFS error code.

This change value-initialises both, matching DelResponse, MKDirResponse and ListDirResponse in the same file, and assign status on both paths.

The visible symptom is a companion app (like InfiniTimeExplorer) reporting a file transfer error ("Error creating file [0]") even when writing the file correctly.

WriteResponse has no default member initialisers and both write handlers
assigned status on only one branch, so the other returned uninitialised
stack memory to the client over BLE:

- commands::WRITE assigned status only on success, so a failed FileOpen
  reported garbage. The ternary was also dead code, as res is known to be
  0 inside that branch.
- commands::WRITE_DATA assigned status only on failure, so every
  successful chunk reported garbage, which readily looks like a negative
  LittleFS error code.

Value-initialise both, matching DelResponse, MKDirResponse and
ListDirResponse in the same file, and assign status on both paths.

The visible symptom is a companion app reporting a file transfer error
against a watch that is writing the file correctly.
@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

@JoeStrout

Copy link
Copy Markdown
Contributor Author

Note: ReadResponse and the other response structs are also declared without {}, so their padding fields go out over the air as uninitialized stack bytes. Harmless functionally, but it is a small information leak. It might be worth fixing just on general principles — happy to add this to my PR if you like.

@DavisNT

DavisNT commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This PR actually fixed resources update via Gadgetbridge.
Tested multiple times.

Also the existing code has a ternary if inside an if block with the same condition, suggesting a human error.

@mark9064, @NeroBurner Could it be possible for you to review and merge this?

resp.status = (res == 0) ? 0x01 : (int8_t) res;
resp.status = 0x01;
} else {
resp.status = (int8_t) res;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Althoug the original had a c stype cast I prever to have C++ style static_cast here please

@NeroBurner NeroBurner added the bug Something isn't working label Oct 29, 2026
@NeroBurner NeroBurner added this to the 1.17.0 milestone Oct 29, 2026
@DavisNT

DavisNT commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@NeroBurner I have contacted @JoeStrout via e-mail and he mentioned he probably couldn't get to this until the
week after next and that we are welcome to do the update on our end if we like.

I have created #2500 which is this exact commit (cherry-picked) with your suggestion (amended). I hope this is OK!

@mark9064

mark9064 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Closing this as #2500 has merged - thanks both

@mark9064 mark9064 closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants