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

fix(nl): fix potential missing NUL terminator #289

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

aloisklink
Copy link
Contributor

When compiling with -DCMAKE_BUILD_TYPE=Release, we get a -Wstringop-truncation warning.

This is because when strncpy exits early because the input string is too long, it DOES NOT copy a NUL terminator. Instead, we need to manually setup a NUL terminator ourselves.


Side-note, I've been trying to use NULL to denote NULL (aka ptr type) and NUL/␀ to denote '\0' (aka char/byte type). That seems to be the convention for C programmers.

When compiling with `-DCMAKE_BUILD_TYPE=Release`, we get a
`-Wstringop-truncation` warning.

This is because when strncpy exits early because the input
string is too long, it **DOES NOT** copy a nul terminator.
Instead, we need to manually setup a nul terminator ourselves.
@aloisklink aloisklink added the bug Something isn't working label Sep 20, 2022
@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Merging #289 (62f649b) into main (f7173e4) will increase coverage by 0.94%.
The diff coverage is 100.00%.

❗ Current head 62f649b differs from pull request most recent head 12496be. Consider uploading reports for the commit 12496be to get more accurate results

@@            Coverage Diff             @@
##             main     #289      +/-   ##
==========================================
+ Coverage   49.26%   50.20%   +0.94%     
==========================================
  Files         116      116              
  Lines       18629    19249     +620     
==========================================
+ Hits         9177     9664     +487     
- Misses       9452     9585     +133     
Impacted Files Coverage Δ
src/utils/nl.c 10.07% <100.00%> (-0.62%) ⬇️
tests/supervisor/test_sockctl_server.c 94.00% <0.00%> (+0.09%) ⬆️
tests/utils/test_os.c 99.19% <0.00%> (+0.82%) ⬆️
tests/ap/test_hostapd.c 95.95% <0.00%> (+3.10%) ⬆️
tests/ap/test_ap_service.c 93.90% <0.00%> (+3.65%) ⬆️
src/utils/sockctl.c 54.08% <0.00%> (+4.68%) ⬆️
src/utils/os.c 54.11% <0.00%> (+7.44%) ⬆️
tests/capture/middlewares/test_sqlite_header.c 89.79% <0.00%> (+14.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@aloisklink aloisklink merged commit c9ecef2 into main Sep 21, 2022
@aloisklink aloisklink deleted the fix/string-NULL-truncation branch September 21, 2022 10:00
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.

2 participants