-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: fix NULL valuestring error #848
Conversation
Fix NULL valuestring problem in cJSON_SetValuestring. This fixes DaveGamble#839 and CVE-2024-31755 Related issue DaveGamble#845
I think passing a NULL |
Honestly, I'm not sure. I haven't fully grokked the way cJSON is designed yet. Maybe my initial issue was opened in haste. Random thoughts:
With the way cJSON is designed, it wouldn't be out of character to just return as is now being done. |
Yet another approach would be to replace the null with an empty string. A copy is made anyways, right? So you could just allocate space for a "" string instead of setting null. Might work well. But with the number of null checks in the codebase, it's not like it's allergic to nulls anyways. I personally would probably be most inclined to crash on null being set but via an assert. But that's just not the style of cJSON and may go against its goals. |
Personally I do not like this idea. Setting empty string when passing NULL looks weird. But my ears are always open.
+1 I think we should focus on these:
|
Yeah honestly, to the embarrasement of my former self, one good option is indeed to:
Of course this can be surprising since the function isn't named 'TrySetValuestring' but that's just how cJSON is. |
Considering setting
+1 Maybe I should close this PR and just update the comment above the code. |
Fix NULL valuestring problem in cJSON_SetValuestring. This fixes #839 and CVE-2024-31755
Related issue #845