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

Replace all calls to strncpy with strlcpy, use strdup more, expose strlcat #3866

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

CookiePLMonster
Copy link
Contributor

@CookiePLMonster CookiePLMonster commented Sep 2, 2024

What's new

This PR improves the consistency of string copy calls, removing all uses of strncpy and strcat, at least from the code that isn't in submodules. strlcpy is preferable over strncpy, because it doesn't needlessly zero the remaining destination buffer, and it ensures null-termination.

Because strlcat is already used in mjs, I exposed it in the API. Please check if this is fine.

To make buffer sizes consistent, I modified the following constants to include the space for the null terminator. Please check if this is fine:

  • IBUTTON_KEY_NAME_SIZE
  • INFRARED_MAX_BUTTON_NAME_LENGTH
  • INFRARED_MAX_REMOTE_NAME_LENGTH
  • MAX_TEXT_INPUT_LEN

Verification

  • Run a full suite of tests.

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

@skotopes skotopes marked this pull request as draft September 6, 2024 12:16
@skotopes
Copy link
Member

skotopes commented Sep 6, 2024

Un-draft when ready

@CookiePLMonster CookiePLMonster marked this pull request as ready for review September 7, 2024 15:10
…rlcat

strlcpy doesn't zero the buffer and ensures null termination,
just like snprintf

strlcat is already used by mjs and it's a safe alternative to strcat,
so it should be OK to expose to apps
@skotopes skotopes merged commit 8672a1d into flipperdevices:dev Sep 7, 2024
11 checks passed
@CookiePLMonster CookiePLMonster deleted the strlcpy-upgrades branch September 7, 2024 16:21
ofabel pushed a commit to ofabel/flipperzero-firmware that referenced this pull request Sep 26, 2024
…rlcat (flipperdevices#3866)

strlcpy doesn't zero the buffer and ensures null termination,
just like snprintf

strlcat is already used by mjs and it's a safe alternative to strcat,
so it should be OK to expose to apps
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.

2 participants