Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
commit 1c63e38a8878d24a011f37f4d1f13865f5bb5aa6
Author: Dave Cottlehuber <dch@FreeBSD.org>
Date: Fri Jun 11 08:10:42 2021 +0000
ftp/curl: build with contentious patch from PR#7039
diff --git ftp/curl/Makefile ftp/curl/Makefile
index 0e979ef5a475..89cba3031c7c 100644
--- ftp/curl/Makefile
+++ ftp/curl/Makefile
@@ -2,6 +2,7 @@
PORTNAME= curl
PORTVERSION= 7.77.0
+PORTREVISION= 1
CATEGORIES= ftp net www
MASTER_SITES= https://curl.se/download/ \
https://github.com/curl/curl/releases/download/curl-${PORTVERSION:S|.|_|g}/
diff --git ftp/curl/files/patch-docs_URL-SYNTAX.md ftp/curl/files/patch-docs_URL-SYNTAX.md
new file mode 100644
index 000000000000..e0ade098cee5
--- /dev/null
+++ ftp/curl/files/patch-docs_URL-SYNTAX.md
@@ -0,0 +1,18 @@
+--- docs/URL-SYNTAX.md.orig 2021-05-25 08:00:20 UTC
++++ docs/URL-SYNTAX.md
+@@ -168,6 +168,15 @@ brackets). For example:
+
+ http://[2001:1890:1112:1::20]/
+
++### "localhost"
++
++Starting in curl 7.77.0, curl will use loopback IP addresses for the name
++`localhost`: `127.0.0.1` and `::1`. It will not try to resolve the name using
++the resolver functions.
++
++This is done to make sure the host accessed is truly the localhost - the local
++machine.
++
+ ### IDNA
+
+ If curl was built with International Domain Name (IDN) support, it can also
diff --git ftp/curl/files/patch-lib_hostip.c ftp/curl/files/patch-lib_hostip.c
new file mode 100644
index 000000000000..2f43bad77579
--- /dev/null
+++ ftp/curl/files/patch-lib_hostip.c
@@ -0,0 +1,99 @@
+--- lib/hostip.c.orig 2021-05-25 22:25:24 UTC
++++ lib/hostip.c
+@@ -63,6 +63,7 @@
+ #include "multiif.h"
+ #include "doh.h"
+ #include "warnless.h"
++#include "strcase.h"
+ /* The last 3 #include files should be in this order */
+ #include "curl_printf.h"
+ #include "curl_memory.h"
+@@ -460,6 +461,75 @@ Curl_cache_addr(struct Curl_easy *data,
+ return dns;
+ }
+
++#ifdef ENABLE_IPV6
++/* return a static IPv6 resolve for 'localhost' */
++static struct Curl_addrinfo *get_localhost6(int port)
++{
++ struct Curl_addrinfo *ca;
++ const size_t ss_size = sizeof(struct sockaddr_in6);
++ const size_t hostlen = strlen("localhost");
++ struct sockaddr_in6 sa6;
++ unsigned char ipv6[16];
++ unsigned short port16 = (unsigned short)(port & 0xffff);
++ ca = calloc(sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1, 1);
++ if(!ca)
++ return NULL;
++
++ sa6.sin6_family = AF_INET6;
++ sa6.sin6_port = htons(port16);
++ sa6.sin6_flowinfo = 0;
++ sa6.sin6_scope_id = 0;
++ Curl_inet_pton(AF_INET6, "::1", ipv6);
++ memcpy(&sa6.sin6_addr, ipv6, sizeof(ipv6));
++
++ ca->ai_flags = 0;
++ ca->ai_family = AF_INET6;
++ ca->ai_socktype = SOCK_STREAM;
++ ca->ai_protocol = IPPROTO_TCP;
++ ca->ai_addrlen = (curl_socklen_t)ss_size;
++ ca->ai_next = NULL;
++ ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo));
++ memcpy(ca->ai_addr, &sa6, ss_size);
++ ca->ai_canonname = (char *)ca->ai_addr + ss_size;
++ strcpy(ca->ai_canonname, "localhost");
++ return ca;
++}
++#else
++#define get_localhost6(x) NULL
++#endif
++
++/* return a static IPv4 resolve for 'localhost' */
++static struct Curl_addrinfo *get_localhost(int port)
++{
++ struct Curl_addrinfo *ca;
++ const size_t ss_size = sizeof(struct sockaddr_in);
++ const size_t hostlen = strlen("localhost");
++ struct sockaddr_in sa;
++ unsigned int ipv4;
++ unsigned short port16 = (unsigned short)(port & 0xffff);
++ ca = calloc(sizeof(struct Curl_addrinfo) + ss_size + hostlen + 1, 1);
++ if(!ca)
++ return NULL;
++
++ sa.sin_family = AF_INET;
++ sa.sin_port = htons(port16);
++ Curl_inet_pton(AF_INET, "127.0.0.1", (char *)&ipv4);
++ memcpy(&sa.sin_addr, &ipv4, sizeof(ipv4));
++
++ ca->ai_flags = 0;
++ ca->ai_family = AF_INET;
++ ca->ai_socktype = SOCK_STREAM;
++ ca->ai_protocol = IPPROTO_TCP;
++ ca->ai_addrlen = (curl_socklen_t)ss_size;
++ ca->ai_next = NULL;
++ ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo));
++ memcpy(ca->ai_addr, &sa, ss_size);
++ ca->ai_canonname = (char *)ca->ai_addr + ss_size;
++ strcpy(ca->ai_canonname, "localhost");
++ ca->ai_next = get_localhost6(port);
++ return ca;
++}
++
+ /*
+ * Curl_resolv() is the main name resolve function within libcurl. It resolves
+ * a name and returns a pointer to the entry in the 'entry' argument (if one
+@@ -584,9 +654,10 @@ enum resolve_t Curl_resolv(struct Curl_easy *data,
+ if(!Curl_ipvalid(data, conn))
+ return CURLRESOLV_ERROR;
+
+- if(allowDOH && data->set.doh && !ipnum) {
++ if(strcasecompare(hostname, "localhost"))
++ addr = get_localhost(port);
++ else if(allowDOH && data->set.doh && !ipnum)
+ addr = Curl_doh(data, hostname, port, &respwait);
+- }
+ else {
+ /* If Curl_getaddrinfo() returns NULL, 'respwait' might be set to a
+ non-zero value indicating that we need to wait for the response to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment