-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
feat: replace occurences of strncpy to strlcpy #4636
Conversation
|
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
9cc7e7c | 1231.84 ms | 1245.24 ms | 13.41 ms |
8e76be4 | 1272.67 ms | 1286.38 ms | 13.71 ms |
2401cbd | 1219.49 ms | 1250.14 ms | 30.65 ms |
e8b14db | 1193.58 ms | 1225.56 ms | 31.98 ms |
5d6ce0e | 1227.57 ms | 1241.08 ms | 13.51 ms |
d8cc6ae | 1228.13 ms | 1253.86 ms | 25.73 ms |
ec879f7 | 1304.84 ms | 1337.04 ms | 32.20 ms |
c677654 | 1228.02 ms | 1248.65 ms | 20.63 ms |
7bb0873 | 1193.70 ms | 1222.74 ms | 29.04 ms |
038edae | 1223.35 ms | 1246.78 ms | 23.43 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
9cc7e7c | 22.84 KiB | 403.14 KiB | 380.29 KiB |
8e76be4 | 20.76 KiB | 427.66 KiB | 406.89 KiB |
2401cbd | 22.85 KiB | 408.85 KiB | 386.00 KiB |
e8b14db | 20.76 KiB | 401.60 KiB | 380.84 KiB |
5d6ce0e | 22.85 KiB | 405.38 KiB | 382.53 KiB |
d8cc6ae | 21.58 KiB | 699.25 KiB | 677.67 KiB |
ec879f7 | 21.58 KiB | 669.68 KiB | 648.10 KiB |
c677654 | 22.30 KiB | 748.66 KiB | 726.36 KiB |
7bb0873 | 22.85 KiB | 407.09 KiB | 384.24 KiB |
038edae | 21.58 KiB | 678.19 KiB | 656.61 KiB |
Previous results on branch: philprime/strncpy-replacement
Startup times
Revision | Plain | With Sentry | Diff |
---|---|---|---|
12db161 | 1227.21 ms | 1242.79 ms | 15.58 ms |
30fe95a | 1230.39 ms | 1243.60 ms | 13.22 ms |
d747559 | 1237.35 ms | 1253.76 ms | 16.41 ms |
c1ccd22 | 1223.02 ms | 1244.00 ms | 20.98 ms |
51c07c7 | 1244.06 ms | 1261.04 ms | 16.98 ms |
83a0223 | 1243.98 ms | 1257.29 ms | 13.31 ms |
428b027 | 1236.82 ms | 1256.59 ms | 19.78 ms |
3ec7df9 | 1225.36 ms | 1247.29 ms | 21.93 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
12db161 | 22.31 KiB | 757.18 KiB | 734.88 KiB |
30fe95a | 22.31 KiB | 757.18 KiB | 734.87 KiB |
d747559 | 22.31 KiB | 760.76 KiB | 738.44 KiB |
c1ccd22 | 22.31 KiB | 758.83 KiB | 736.52 KiB |
51c07c7 | 22.31 KiB | 765.80 KiB | 743.49 KiB |
83a0223 | 22.31 KiB | 760.68 KiB | 738.36 KiB |
428b027 | 22.31 KiB | 760.74 KiB | 738.43 KiB |
3ec7df9 | 22.31 KiB | 756.53 KiB | 734.22 KiB |
One thing I'd recommend here is to wrap whatever function we actually want to use in a function we control, to make it easier to test and potentially change later. It could be the case that My understanding after reading the docs is that
from https://linux.die.net/man/3/strlcpy:
I guess this is what this line of code is trying to replicate: https://github.com/getsentry/sentry-cocoa/pull/4636/files#diff-de0cc4487a50688dff672b8cd13b3901fdbf09abe93afa34b54bd561d1796fe8L1260 and I also just saw we actually already had another function to do this: https://github.com/getsentry/sentry-cocoa/pull/4636/files#diff-898d2165aedeeac3e2023d294e4bffee79b96b5c04d9d9d5be7e7593d4eb9aeeL21-L27 This is why a wrapper function is my preference, we can hide all these details and keep things consistent. If we have places that move data from char arrays back to buffers, we should also have a wrapper function for that as well. |
Thanks @armcknight for reviewing the PR. As requested in the issue and mentioned by you, we need to make sure the changes do not break the SDK. That's why I went ahead and started adding additional unit tests.
I was thinking of the same, and yes we might need to extend the buffers at some places by one character, if it actually uses the full buffer length. I also found the function sentry-cocoa/Sources/SentryCrash/Reporting/Filters/Tools/SentryStringUtils.h Lines 21 to 27 in 419f1d4
TL;DR: I added todos to the description what is left to do. In total I found 7 uses of
sentry-cocoa/Sources/SentryCrash/Recording/SentryCrashReport.c Lines 1474 to 1479 in 419f1d4
sentry-cocoa/Sources/SentryCrash/Recording/SentryCrashReportFixer.c Lines 54 to 68 in 419f1d4
sentry-cocoa/Sources/SentryCrash/Recording/Tools/SentryCrashFileUtils.c Lines 155 to 167 in 419f1d4
sentry-cocoa/Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c Lines 1259 to 1260 in 419f1d4
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4636 +/- ##
=============================================
+ Coverage 90.588% 91.232% +0.643%
=============================================
Files 623 622 -1
Lines 71285 71660 +375
Branches 25359 26101 +742
=============================================
+ Hits 64576 65377 +801
+ Misses 6617 6184 -433
- Partials 92 99 +7
... and 30 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work to make the changes and write the tests that cover a lot of implementation code.
We use a common pattern of sut
(system under test) which you might be able to use to refactor some of the tests. I know there's a tension between DRY and self-contained test logic. Figured I'd just offer it up as food for thought.
Overall I think the changes are fine so this has my approval. I merely offer some suggestions and comments along the way.
Tests/SentryTests/SentryCrash/SentryCrashMonitor_CppException_Tests.mm
Outdated
Show resolved
Hide resolved
Tests/SentryTests/SentryCrash/SentryCrashMonitor_CppException_Tests.mm
Outdated
Show resolved
Hide resolved
Tests/SentryTests/SentryCrash/SentryCrashMonitor_CppException_Tests.mm
Outdated
Show resolved
Hide resolved
Tests/SentryTests/SentryCrash/SentryCrashMonitor_CppException_Tests.mm
Outdated
Show resolved
Hide resolved
Co-authored-by: Andrew McKnight <[email protected]>
Co-authored-by: Andrew McKnight <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have nothing to add as @armcknight knowledge on C is way more extensive than mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a few smoke tests, if the crash reports end up successfully in Sentry via the sample app via Testflight, would reduce the chance of bugs. We should test this with the following buttons in the iOS-Swift sample app: Throw FatalError, Crash the app, force unwrap optional, and an unhandled CPP exception, which isn't in the sample app I believe. Finally, we should do a beta release with our dogfooding app before releasing this.
Passing smoke tests performed manually with errors reported in Sentry: Sample App - macOS-Swift:
Sample App - iOS-Swift:
|
These also show up in the Testflight crashes as expected:
LGTM? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work @philprime !
📜 Description
Renames all occurences of
strncpy
withstrlcpy
as explained in #2783.💡 Motivation and Context
I looked all the occurences and tried to create additional unit tests where applicable. Some of the cases using
strlcpy
have larger buffer sizes set, i.e.SentryCrashFU_MAX_PATH_LENGTH
is set to500
, but I was not able to file with a longer name because the OS throws NSPOSIXErrorDomain, code 63, indicating that the file system does not support such long files.Closes #2783
💚 How did you test it?
📝 Checklist
You have to check all boxes before merging:
sendDefaultPII
is enabled.🔮 Next steps
CPPExceptionTerminate
to test ifstrncpy_safe
andstrlcpy
do the samesentrycrashreport_writeRecrashReport
deletePathContents
for too long file paths