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

Fix unchecked malloc #1602

Merged
merged 2 commits into from
Feb 6, 2024
Merged

Conversation

garrettgu10
Copy link
Collaborator

The original code did not check if the allocation succeeded, leading to possible issues if malloc() returns null.

This PR should fix that by simply replacing the malloc with a stack allocation.

@garrettgu10 garrettgu10 requested review from a team as code owners February 1, 2024 16:12
Copy link

github-actions bot commented Feb 1, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@garrettgu10
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 1, 2024
@garrettgu10
Copy link
Collaborator Author

recheck

@jclee
Copy link
Contributor

jclee commented Feb 1, 2024

Just naively wondering... If the malloc is sometimes failing, is it just due to running out of heap space when trying to allocate a large block of memory? If so, wouldn't allocating on the stack just introduce a different failure mode where stack space is exhausted?

@kentonv
Copy link
Member

kentonv commented Feb 1, 2024

@jclee The malloc is not ever failing. This was flagged by a security scanner tool. In practice we have overcommit enabled so mallocs never fail. But we also shouldn't be using malloc anywhere in KJ code.

src/workerd/io/worker.c++ Outdated Show resolved Hide resolved
@garrettgu10 garrettgu10 merged commit 18eea99 into cloudflare:main Feb 6, 2024
11 checks passed
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.

4 participants