-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
base: main
Are you sure you want to change the base?
Conversation
|
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
ca507ec | 1224.43 ms | 1246.04 ms | 21.61 ms |
a176fc4 | 1226.24 ms | 1247.50 ms | 21.26 ms |
2a769ba | 1217.92 ms | 1239.78 ms | 21.86 ms |
fdfe96b | 1227.90 ms | 1242.56 ms | 14.66 ms |
154f795 | 1250.38 ms | 1274.54 ms | 24.16 ms |
9d56232 | 1192.09 ms | 1228.86 ms | 36.77 ms |
f8fc36d | 1226.31 ms | 1247.80 ms | 21.49 ms |
16450b8 | 1196.33 ms | 1217.26 ms | 20.93 ms |
2eb78be | 1242.15 ms | 1259.00 ms | 16.85 ms |
7c5d161 | 1224.38 ms | 1249.66 ms | 25.28 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
ca507ec | 21.58 KiB | 616.76 KiB | 595.17 KiB |
a176fc4 | 22.84 KiB | 403.24 KiB | 380.39 KiB |
2a769ba | 21.58 KiB | 683.64 KiB | 662.05 KiB |
fdfe96b | 20.76 KiB | 419.70 KiB | 398.95 KiB |
154f795 | 20.76 KiB | 435.25 KiB | 414.49 KiB |
9d56232 | 20.76 KiB | 425.80 KiB | 405.04 KiB |
f8fc36d | 20.76 KiB | 419.70 KiB | 398.94 KiB |
16450b8 | 22.85 KiB | 410.98 KiB | 388.13 KiB |
2eb78be | 21.58 KiB | 706.97 KiB | 685.39 KiB |
7c5d161 | 20.76 KiB | 414.44 KiB | 393.68 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 |
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 |
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
|
📜 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