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

Add strengthen the protection of strlen in cJSON_ParseWithOpts #921

Closed
wants to merge 1 commit into from

Conversation

zjykymt
Copy link

@zjykymt zjykymt commented Jan 2, 2025

Dear maintainer,

when using flash's mmap method to access json strings, can strengthen the protection of strlen when flash data is all 0xff

when using flash's mmap method to access json strings, can strengthen the protection of strlen when flash data is all 0xff
@zjykymt zjykymt changed the title strengthen the protection of strlen Add strengthen the protection of strlen in cJSON_ParseWithOpts Jan 2, 2025
@imaami
Copy link

imaami commented Jan 25, 2025

What do mmap() and strlen() and 0xff values have to do with cJSON_ParseWithOpts()? Have you run unit tests on your branch? Do you realize that your change would make cJSON_ParseWithOpts() unable to parse JSON strings or skip leading whitespace?

@zjykymt
Copy link
Author

zjykymt commented Feb 6, 2025

This modification will prevent parsing of JSON strings with leading whitespace

When dealing with Flash regions that may contain all 0xFF values, using the cJSON_ParseWithLength function is a prudent choice.

This function allows you to specify the exact length of the data to be parsed, ensuring that only valid data is processed.

This approach is particularly important when handling Flash regions that might contain invalid or uninitialized data, as directly using cJSON_Parse could lead to parsing failures or memory access errors.

@zjykymt zjykymt closed this Feb 6, 2025
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