Skip to content

Clear the default flood scope's old name when a shorter one is set 🤖🤖 - #3899

Open
hamsolodev wants to merge 1 commit into
meshcore-dev:devfrom
hamsolodev:fix/default-scope-name-tail
Open

hamsolodev wants to merge 1 commit into
meshcore-dev:devfrom
hamsolodev:fix/default-scope-name-tail

Conversation

@hamsolodev

Copy link
Copy Markdown

CMD_SET_DEFAULT_FLOOD_SCOPE copies the new name into _prefs.default_scope_name with strcpy (examples/companion_radio/MyMesh.cpp:1983 on dev, 1993 at companion-v1.18.0), so when the new name is shorter than the old one, the bytes after its NUL keep the old name's tail. CMD_GET_DEFAULT_FLOOD_SCOPE then sends all 31 bytes of the field (MyMesh.cpp:1999 on dev). The firmware itself reads the name only up to the NUL, and the JSON prefs file is written only up to the NUL, so the tail lives in RAM until the next boot; but a client that reads the whole field shows a joined name.

The change copies with StrHelper::strzcpy, which NUL-pads the rest of the field, so nothing of the old name is left. It is one line; the clear branch already memsets the field.

Verified on the host build (MeshBench, companion-v1.18.0 with and without the change), with a client I'm writing's raw frames: set #au-vic-gipps, then #au, then read it back.

Before (the name field is the 31 bytes after 1c):

sent     3f23617500000000000000000000000000000000000000000000000000000000f7749b8eaab70ec2617282f0610cd167
answered 00
sent     40
answered 1c236175007669632d6769707073000000000000000000000000000000000000f7749b8eaab70ec2617282f0610cd167
         -> "#au\0vic-gipps"

After:

sent     3f23617500000000000000000000000000000000000000000000000000000000f7749b8eaab70ec2617282f0610cd167
answered 00
sent     40
answered 1c23617500000000000000000000000000000000000000000000000000000000f7749b8eaab70ec2617282f0610cd167
         -> "#au"

The same kind of stale bytes after a NUL, left alone here to keep this to one fix:

  • CMD_GET_CHANNEL copies the channel name into out_frame with strcpy and sends 32 bytes (MyMesh.cpp:1749 on dev), so the bytes after the name's NUL are whatever an earlier frame left in out_frame.
  • CMD_SET_CHANNEL copies the name into a stack ChannelDetails with StrHelper::strncpy, which doesn't pad (MyMesh.cpp:1762), and saveChannels writes all 32 bytes (DataStore.cpp:358), so uninitialised stack bytes reach the channels file.

Fixes #3891

meshcore_py's side of the display (it reads the field to its end, not to the first NUL) is meshcore-dev/meshcore_py#128, part of meshcore-dev/meshcore_py#119.

CMD_SET_DEFAULT_FLOOD_SCOPE copied the new name over the old one with
strcpy, leaving the bytes after its NUL as they were. A shorter name set
over a longer one kept the longer one's tail, and CMD_GET_DEFAULT_FLOOD_SCOPE
sends all 31 bytes of the field. Copy with StrHelper::strzcpy, which
NUL-pads the rest of the field.

Fixes meshcore-dev#3891

This branch has not been deployed

No deployments
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