]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ngtcp2: fix unwanted close of file descriptor 0
authorStefan Eissing <stefan@eissing.org>
Thu, 23 Feb 2023 15:54:02 +0000 (16:54 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 24 Feb 2023 07:43:35 +0000 (08:43 +0100)
... causing macOS to hand out 0 as next socket handle and failing on
further operations.

Reported-by: Sergey Fionov
Fixes #10593
Closes #10595

lib/cf-socket.c
lib/vquic/curl_ngtcp2.c

index 2549f3456ba1ce4d54079e9f40e833547852ae6f..07ff2329a7294ac3f0823f61c60950dbb28b5871 100644 (file)
@@ -253,19 +253,6 @@ static CURLcode socket_open(struct Curl_easy *data,
   else {
     /* opensocket callback not set, so simply create the socket now */
     *sockfd = socket(addr->family, addr->socktype, addr->protocol);
-    if(!*sockfd && addr->socktype == SOCK_DGRAM) {
-      /* This is icky and seems, at least, to happen on macOS:
-       * we get sockfd == 0 and if called again, we get a valid one > 0.
-       * If we close the 0, we sometimes get failures in multi poll, as
-       * 0 seems also be the fd for the sockpair used for WAKEUP polling.
-       * Very strange. Maybe this code should be ifdef'ed for macOS, but
-       * on "real" OS, fd 0 is stdin and we never see that. So...
-       */
-      fake_sclose(*sockfd);
-      *sockfd = socket(addr->family, addr->socktype, addr->protocol);
-      DEBUGF(infof(data, "QUIRK: UDP socket() gave handle 0, 2nd attempt %d",
-                   (int)*sockfd));
-    }
   }
 
   if(*sockfd == CURL_SOCKET_BAD)
index ffdaeade35023fa17475bf46ae73980f8133b177..aad095c207aabbf4d7a5dc93e285260247abd6ee 100644 (file)
@@ -2127,7 +2127,6 @@ static void cf_ngtcp2_ctx_clear(struct cf_ngtcp2_ctx *ctx)
 
   if(ctx->qlogfd != -1) {
     close(ctx->qlogfd);
-    ctx->qlogfd = -1;
   }
 #ifdef USE_OPENSSL
   if(ctx->ssl)
@@ -2155,6 +2154,7 @@ static void cf_ngtcp2_ctx_clear(struct cf_ngtcp2_ctx *ctx)
     ngtcp2_conn_del(ctx->qconn);
 
   memset(ctx, 0, sizeof(*ctx));
+  ctx->qlogfd = -1;
   ctx->call_data = save;
 }
 
@@ -2470,6 +2470,7 @@ CURLcode Curl_cf_ngtcp2_create(struct Curl_cfilter **pcf,
     result = CURLE_OUT_OF_MEMORY;
     goto out;
   }
+  ctx->qlogfd = -1;
   cf_ngtcp2_ctx_clear(ctx);
 
   result = Curl_cf_create(&cf, &Curl_cft_http3, ctx);