Skip to content

examples: wgetjson: check allocations before use#3606

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Old-Ding:codex/wgetjson-check-allocations
Jul 9, 2026
Merged

examples: wgetjson: check allocations before use#3606
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Old-Ding:codex/wgetjson-check-allocations

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Check wgetjson response, JSON path, request buffer, and POST body allocations before use.
  • Return or propagate allocation failures instead of dereferencing NULL buffers.

Root cause

Several malloc() results in the wgetjson example were used immediately by memcpy(), snprintf(), web_posts_str(), web_post_str(), or webclient_perform() without first checking whether allocation succeeded. Low-memory paths could therefore crash before the existing cleanup logic ran.

Testing

  • git diff --check
  • git show --stat --check --format=fuller HEAD

Not run: local compile, because this environment does not have make, cmake, gcc, clang, or cc available.

xiaoxiang781216
xiaoxiang781216 previously approved these changes Jul 6, 2026
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Old-Ding please fix:

c1da0ee1f examples: wgetjson: check allocations before use
../nuttx/tools/checkpatch.sh -c -u -m -g 4d5f60005c6d91c76e4a585fe3102aab50119ec6..HEAD
❌ Missing git commit message
Used config files:
    1: .codespellrc
Some checks failed. For contributing guidelines, see:
  https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md
Error: Process completed with exit code 1.

Comment thread examples/wgetjson/wgetjson_main.c Outdated

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Old-Ding, please git commit message and valid email as git commit signature.

@Old-Ding Old-Ding force-pushed the codex/wgetjson-check-allocations branch 2 times, most recently from 3778619 to 1fcddcd Compare July 8, 2026 06:17
Several malloc() results in the wgetjson example were used before checking for allocation failure, which could crash low-memory paths before cleanup ran.

Return or propagate allocation errors before using the allocated buffers. Use explicit NULL comparisons for the new pointer checks to match review feedback.

Signed-off-by: Old-Ding <ai.neo.ae86@gmail.com>
@Old-Ding Old-Ding force-pushed the codex/wgetjson-check-allocations branch from 1fcddcd to cf46b8b Compare July 8, 2026 13:50
@xiaoxiang781216 xiaoxiang781216 merged commit 17b028e into apache:master Jul 9, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants