Skip to content

Commit

Permalink
Add patches from upstream to avoid libflatpak crash with curl 8.10.x
Browse files Browse the repository at this point in the history
Closes: #1082121
  • Loading branch information
smcv committed Sep 19, 2024
1 parent 66bd9ba commit f509eaa
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
31 changes: 31 additions & 0 deletions debian/patches/curl-Assert-that-curl_multi_assign-worked.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From: Colin Walters <[email protected]>
Date: Wed, 18 Sep 2024 13:21:27 -0400
Subject: curl: Assert that curl_multi_assign worked

ref https://github.com/ostreedev/ostree/issues/3299

This won't fix that issue, but *if* this assertion triggers
it should give us a better idea of the possible codepaths
where it is happening.

Signed-off-by: Colin Walters <[email protected]>
Origin: upstream, 2024.8, commit:472d9d493a3e4a08415da4c337a7e831e0c5a5e2
Bug-Debian: https://bugs.debian.org/1082121
---
src/libostree/ostree-fetcher-curl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c
index d690289..5808c45 100644
--- a/src/libostree/ostree-fetcher-curl.c
+++ b/src/libostree/ostree-fetcher-curl.c
@@ -517,7 +517,8 @@ addsock (curl_socket_t s, CURL *easy, int action, OstreeFetcher *fetcher)
fdp->refcount = 1;
fdp->fetcher = fetcher;
setsock (fdp, s, action, fetcher);
- curl_multi_assign (fetcher->multi, s, fdp);
+ CURLMcode rc = curl_multi_assign (fetcher->multi, s, fdp);
+ g_assert_cmpint (rc, ==, CURLM_OK);
g_hash_table_add (fetcher->sockets, fdp);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From: Colin Walters <[email protected]>
Date: Wed, 18 Sep 2024 13:41:59 -0400
Subject: curl: Make socket callback during cleanup into no-op

Because curl_multi_cleanup may invoke callbacks, we effectively have
some circular references going on here. See discussion in

https://github.com/curl/curl/issues/14860

Basically what we do is the socket callback libcurl may invoke into a no-op when
we detect we're finalizing. The data structures are owned by this object and
not by the callbacks, and will be destroyed below. Note that
e.g. g_hash_table_unref() may itself invoke callbacks, which is where
some data is cleaned up.

Signed-off-by: Colin Walters <[email protected]>
Origin: upstream, 2024.8, commit:4d755a85225ea0a02d4580d088bb8a97138cb040
Bug: https://github.com/ostreedev/ostree/issues/3299
Bug-Debian: https://bugs.debian.org/1082121
---
src/libostree/ostree-fetcher-curl.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c
index 5808c45..1872974 100644
--- a/src/libostree/ostree-fetcher-curl.c
+++ b/src/libostree/ostree-fetcher-curl.c
@@ -78,6 +78,7 @@ struct OstreeFetcher
struct curl_slist *extra_headers;
int tmpdir_dfd;
bool force_anonymous;
+ bool finalizing; // Set if we're in the process of teardown
char *custom_user_agent;
guint32 opt_low_speed_limit;
guint32 opt_low_speed_time;
@@ -180,6 +181,15 @@ _ostree_fetcher_finalize (GObject *object)
{
OstreeFetcher *self = OSTREE_FETCHER (object);

+ // Because curl_multi_cleanup may invoke callbacks, we effectively have
+ // some circular references going on here. See discussion in
+ // https://github.com/curl/curl/issues/14860
+ // Basically what we do is make most callbacks libcurl may invoke into no-ops when
+ // we detect we're finalizing. The data structures are owned by this object and
+ // not by the callbacks, and will be destroyed below. Note that
+ // e.g. g_hash_table_unref() may itself invoke callbacks, which is where
+ // some data is cleaned up.
+ self->finalizing = true;
curl_multi_cleanup (self->multi);
g_free (self->remote_name);
g_free (self->tls_ca_db_path);
@@ -529,6 +539,10 @@ sock_cb (CURL *easy, curl_socket_t s, int what, void *cbp, void *sockp)
OstreeFetcher *fetcher = cbp;
SockInfo *fdp = (SockInfo *)sockp;

+ // We do nothing if we're in the process of teardown; see below.
+ if (fetcher->finalizing)
+ return 0;
+
if (what == CURL_POLL_REMOVE)
{
if (!g_hash_table_remove (fetcher->sockets, fdp))
2 changes: 2 additions & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
curl-Assert-that-curl_multi_assign-worked.patch
curl-Make-socket-callback-during-cleanup-into-no-op.patch
debian/Skip-test-pull-repeated-during-CI.patch
debian/test-sysroot-Skip-on-s390x-by-default.patch
debian/Skip-test-admin-deploy-uboot.sh-on-s390x.patch

0 comments on commit f509eaa

Please sign in to comment.