Skip to content

curl: Fix use after free on a POST request - #2863

Merged
privat merged 2 commits into
nitlang:masterfrom
xymus:curl-copy-string
Sep 2, 2026
Merged

curl: Fix use after free on a POST request#2863
privat merged 2 commits into
nitlang:masterfrom
xymus:curl-copy-string

Conversation

@xymus

@xymus xymus commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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 perform work. 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.

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>
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Test Results

    67 files     317 suites   15m 35s ⏱️
14 236 tests 13 689 ✅ 547 💤 0 ❌
14 310 runs  13 748 ✅ 562 💤 0 ❌

Results for commit 45e7d48.

♻️ This comment has been updated with latest results.

@xymus
xymus requested a review from privat September 1, 2026 19:33
@privat
privat merged commit e1f4035 into nitlang:master Sep 2, 2026
41 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.

2 participants