curl: Fix use after free on a POST request - #2863
Merged
Merged
Conversation
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
The string passed to libcurl is a copy made by `to_cstring`, it was unreachable from Nit and could be freed by the GC before libcurl reads it with `postfields`. Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Test Results 67 files 317 suites 15m 35s ⏱️ Results for commit 45e7d48. ♻️ This comment has been updated with latest results. |
xymus
force-pushed
the
curl-copy-string
branch
from
September 1, 2026 18:29
8f6d430 to
45e7d48
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When creating a POST request with the curl lib there was a potential use after free depending on when the GC triggered, causing issues in long running apps. We would allocate a C string and pass it to curl, losing a handle to it before triggering the
performwork. If the GC triggered between the two operations curl would read from freed memory.Let's use the curl service that takes ownership of a copy of this string. This is the foolproof solution but isn't ideal as the string content is usually copied twice, but the usual way around it (allocating the C string on the Nit side and releasing it later) would add boiler plate too all call sites.