NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/57179 (occasional pkg_add core dumps)
The following reply was made to PR bin/57179; it has been noted by GNATS.
From: Thomas Klausner <wiz%netbsd.org@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: Taylor R Campbell <riastradh%netbsd.org@localhost>
Subject: Re: bin/57179 (occasional pkg_add core dumps)
Date: Sat, 11 Apr 2026 16:20:21 +0200
--5a4ne2b4mjjpywwl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
This is a mess.
The pkgsrc version and the base version have diverged in lots of small
details.
I've tried merging the changes both ways. It compiles for me with no
warnings on 11.99.5/x86_64.
Please review carefully.
Thanks,
Thomas
--5a4ne2b4mjjpywwl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="src.fetch.diff"
Index: common.c
===================================================================
RCS file: /cvsroot/src/external/bsd/fetch/dist/libfetch/common.c,v
retrieving revision 1.8
diff -u -r1.8 common.c
--- common.c 11 Apr 2026 10:42:32 -0000 1.8
+++ common.c 11 Apr 2026 14:19:07 -0000
@@ -41,14 +41,11 @@
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
-#if defined(HAVE_POLL_H) || defined(NETBSD)
+#if HAVE_POLL_H
#include <poll.h>
-#define HAVE_POLL
#elif HAVE_SYS_POLL_H
-#define HAVE_POLL
#include <sys/poll.h>
#endif
-
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -243,9 +240,7 @@
conn->next_buf = NULL;
conn->next_len = 0;
conn->sd = sd;
-#ifdef HAVE_POLL
conn->buf_events = POLLIN;
-#endif
return (conn);
}
@@ -479,8 +474,7 @@
conn->buf_events = 0;
SSL_set_fd(conn->ssl, conn->sd);
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
- if (!SSL_set_tlsext_host_name(conn->ssl, (char *)(uintptr_t)URL->host))
- {
+ if (!SSL_set_tlsext_host_name(conn->ssl, (char *)(uintptr_t)URL->host)) {
fprintf(stderr,
"TLS server name indication extension failed for host %s\n",
URL->host);
@@ -518,17 +512,16 @@
#endif
}
-#ifdef HAVE_POLL
static int
compute_timeout(const struct timeval *tv)
{
struct timeval cur;
+ int timeout;
gettimeofday(&cur, NULL);
- return (tv->tv_sec - cur.tv_sec) * 1000
- + (tv->tv_usec - cur.tv_usec) / 1000;
+ timeout = (tv->tv_sec - cur.tv_sec) * 1000 + (tv->tv_usec - cur.tv_usec) / 1000;
+ return timeout;
}
-#endif
/*
* Read a character from a connection w/ timeout
@@ -537,11 +530,7 @@
fetch_read(conn_t *conn, char *buf, size_t len)
{
struct timeval timeout_end;
-#ifdef HAVE_POLL
struct pollfd pfd;
-#else
- fd_set readfds;
-#endif
int timeout_cur;
ssize_t rlen;
int r;
@@ -559,16 +548,12 @@
}
if (fetchTimeout) {
-#ifndef HAVE_POLL
- FD_ZERO(&readfds);
-#endif
gettimeofday(&timeout_end, NULL);
timeout_end.tv_sec += fetchTimeout;
}
+ pfd.fd = conn->sd;
for (;;) {
-#ifdef HAVE_POLL
- pfd.fd = conn->sd;
pfd.events = conn->buf_events;
if (fetchTimeout && pfd.events) {
do {
@@ -587,31 +572,6 @@
return (-1);
}
} while (pfd.revents == 0);
-#else
- while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
- struct timeval waittv, now;
- FD_SET(conn->sd, &readfds);
- gettimeofday(&now, NULL);
- waittv.tv_sec = timeout_end.tv_sec - now.tv_sec;
- waittv.tv_usec = timeout_end.tv_usec - now.tv_usec;
- if (waittv.tv_usec < 0) {
- waittv.tv_usec += 1000000;
- waittv.tv_sec--;
- }
- if (waittv.tv_sec < 0) {
- errno = ETIMEDOUT;
- fetch_syserr();
- return (-1);
- }
- errno = 0;
- r = select(conn->sd + 1, &readfds, NULL, NULL, &waittv);
- if (r == -1) {
- if (errno == EINTR && fetchRestartCalls)
- continue;
- fetch_syserr();
- return (-1);
- }
-#endif
}
#ifdef WITH_SSL
if (conn->ssl != NULL) {
Index: common.h
===================================================================
RCS file: /cvsroot/src/external/bsd/fetch/dist/libfetch/common.h,v
retrieving revision 1.4
diff -u -r1.4 common.h
--- common.h 11 Apr 2026 10:42:32 -0000 1.4
+++ common.h 11 Apr 2026 14:19:07 -0000
@@ -54,7 +54,8 @@
#if !defined(__sun) && !defined(__hpux) && !defined(__INTERIX) && \
!defined(__digital__) && !defined(__linux) && !defined(__MINT__) && \
- !defined(__sgi) && !defined(__minix) && !defined(__CYGWIN__)
+ !defined(__sgi) && !defined(__minix) && !defined(__CYGWIN__) && \
+ !defined(_M_XENIX)
#define HAVE_SA_LEN
#endif
Index: ftp.c
===================================================================
RCS file: /cvsroot/src/external/bsd/fetch/dist/libfetch/ftp.c,v
retrieving revision 1.9
diff -u -r1.9 ftp.c
--- ftp.c 11 Apr 2026 10:42:32 -0000 1.9
+++ ftp.c 11 Apr 2026 14:19:07 -0000
@@ -98,6 +98,7 @@
#include "common.h"
#include "ftperr.h"
+static int ftp_cmd(conn_t *, const char *, ...) LIBFETCH_PRINTFLIKE(2, 3);
#define FTP_ANONYMOUS_USER "anonymous"
#define FTP_CONNECTION_ALREADY_OPEN 125
@@ -691,14 +692,13 @@
const char *filename;
size_t filenamelen;
int type;
- int low, pasv, verbose;
+ int pasv, verbose;
int e, sd = -1;
socklen_t l;
char *s;
fetchIO *df;
/* check flags */
- low = CHECK_FLAG('l');
pasv = !CHECK_FLAG('a');
verbose = CHECK_FLAG('v');
@@ -864,6 +864,7 @@
uint16_t p;
#if defined(IPV6_PORTRANGE) || defined(IP_PORTRANGE)
int arg;
+ int low = CHECK_FLAG('l');
#endif
int d;
char hname[INET6_ADDRSTRLEN];
@@ -919,18 +920,21 @@
goto ouch;
}
if (e != FTP_OK) {
- uint8_t aa[sizeof(u.sin6.sin6_addr)];
- memcpy(aa, &u.sin6.sin6_addr, sizeof(aa));
- p = ntohs(u.sin6.sin6_port);
+ unsigned char *ap = (void *)&u.sin6.sin6_addr.s6_addr;
+ uint16_t port = ntohs(u.sin6.sin6_port);
e = ftp_cmd(conn,
- "LPRT %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",
+ "LPRT %d,%d,%u,%u,%u,%u,%u,%u,%u,%u,"
+ "%u,%u,%u,%u,%u,%u,%u,%u,%d,%d,%d\r\n",
6, 16,
- aa[ 0], aa[ 1], aa[ 2], aa[ 3],
- aa[ 4], aa[ 5], aa[ 6], aa[ 7],
- aa[ 8], aa[ 9], aa[10], aa[11],
- aa[12], aa[13], aa[14], aa[15],
- 2,
- ((unsigned int)p >> 8) & 0xff, p & 0xff);
+ (unsigned)ap[0], (unsigned)ap[1],
+ (unsigned)ap[2], (unsigned)ap[3],
+ (unsigned)ap[4], (unsigned)ap[5],
+ (unsigned)ap[6], (unsigned)ap[7],
+ (unsigned)ap[8], (unsigned)ap[9],
+ (unsigned)ap[10], (unsigned)ap[11],
+ (unsigned)ap[12], (unsigned)ap[13],
+ (unsigned)ap[14], (unsigned)ap[15],
+ 2, port >> 8, port & 0xff);
}
break;
default:
@@ -1110,22 +1114,18 @@
ftp_get_proxy(struct url * url, const char *flags)
{
struct url *purl;
- char *p, *fp, *FP, *hp, *HP;
+ char *p;
if (flags != NULL && strchr(flags, 'd') != NULL)
- return NULL;
+ return (NULL);
if (fetch_no_proxy_match(url->host))
- return NULL;
-
- FP = getenv("FTP_PROXY");
- fp = getenv("ftp_proxy");
- HP = getenv("HTTP_PROXY");
- hp = getenv("http_proxy");
+ return (NULL);
- if ((((p = FP) || (p = fp) || (p = HP) || (p = hp))) &&
+ if (((p = getenv("FTP_PROXY")) || (p = getenv("ftp_proxy")) ||
+ (p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
*p && (purl = fetchParseURL(p)) != NULL) {
if (!*purl->scheme) {
- if (fp || FP)
+ if (getenv("FTP_PROXY") || getenv("ftp_proxy"))
strcpy(purl->scheme, SCHEME_FTP);
else
strcpy(purl->scheme, SCHEME_HTTP);
@@ -1134,10 +1134,10 @@
purl->port = fetch_default_proxy_port(purl->scheme);
if (strcasecmp(purl->scheme, SCHEME_FTP) == 0 ||
strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
- return purl;
+ return (purl);
fetchFreeURL(purl);
}
- return NULL;
+ return (NULL);
}
/*
Index: http.c
===================================================================
RCS file: /cvsroot/src/external/bsd/fetch/dist/libfetch/http.c,v
retrieving revision 1.7
diff -u -r1.7 http.c
--- http.c 11 Apr 2026 10:42:32 -0000 1.7
+++ http.c 11 Apr 2026 14:19:07 -0000
@@ -72,10 +72,8 @@
#define _GNU_SOURCE
#endif
-#ifndef _REENTRANT
/* Needed for gmtime_r on Interix */
#define _REENTRANT
-#endif
#if HAVE_CONFIG_H
#include "config.h"
@@ -99,6 +97,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#if defined(__APPLE__)
+#include <xlocale.h> /* for strptime_l */
+#endif
#include <unistd.h>
#include <netinet/in.h>
@@ -139,6 +140,7 @@
#define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599)
+static int http_cmd(conn_t *, const char *, ...) LIBFETCH_PRINTFLIKE(2, 3);
/*****************************************************************************
* I/O functions for decoding chunked streams
@@ -494,6 +496,16 @@
return (hdr);
}
+/* Remove whitespace at the end of the buffer */
+static void
+http_conn_trimright(conn_t *conn)
+{
+ while (conn->buflen &&
+ isspace((unsigned char)conn->buf[conn->buflen - 1]))
+ conn->buflen--;
+ conn->buf[conn->buflen] = '\0';
+}
+
/*
* Get the next header and return the appropriate symbolic code.
*/
@@ -502,13 +514,20 @@
{
int i;
- if (fetch_getln(conn) == -1)
- return (hdr_syserror);
- while (conn->buflen && isspace((unsigned char)conn->buf[conn->buflen - 1]))
- conn->buflen--;
- conn->buf[conn->buflen] = '\0';
+ /*
+ * Have to do the stripping here because of the first line. So
+ * it's done twice for the subsequent lines. No big deal
+ */
+ http_conn_trimright(conn);
+
if (conn->buflen == 0)
return (hdr_end);
+
+ if (fetch_getln(conn) == -1)
+ return (hdr_syserror);
+
+ http_conn_trimright(conn);
+
/*
* We could check for malformed headers but we don't really care.
* A valid header starts with a token immediately followed by a
@@ -538,7 +557,6 @@
locale = strdup(setlocale(LC_TIME, NULL));
if (locale == NULL)
return (-1);
-
setlocale(LC_TIME, "C");
r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
/* XXX should add support for date-2 and date-3 */
@@ -621,13 +639,12 @@
"0123456789+/";
char *str, *dst;
size_t l;
- unsigned int t, r;
+ int t;
l = strlen(src);
if ((str = malloc(((l + 2) / 3) * 4 + 1)) == NULL)
return (NULL);
dst = str;
- r = 0;
while (l >= 3) {
t = (src[0] << 16) | (src[1] << 8) | src[2];
@@ -636,7 +653,7 @@
dst[2] = base64[(t >> 6) & 0x3f];
dst[3] = base64[(t >> 0) & 0x3f];
src += 3; l -= 3;
- dst += 4; r += 4;
+ dst += 4;
}
switch (l) {
@@ -647,7 +664,6 @@
dst[2] = base64[(t >> 6) & 0x3f];
dst[3] = '=';
dst += 4;
- r += 4;
break;
case 1:
t = src[0] << 16;
@@ -655,7 +671,6 @@
dst[1] = base64[(t >> 12) & 0x3f];
dst[2] = dst[3] = '=';
dst += 4;
- r += 4;
break;
case 0:
break;
@@ -804,6 +819,7 @@
#else
errno = EPERM;
#endif
+ fetch_syserr();
goto ouch;
}
@@ -851,7 +867,7 @@
gmtime_r(&last_modified, &tm);
snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4ld %02d:%02d:%02d GMT",
weekdays + tm.tm_wday * 3, tm.tm_mday, months + tm.tm_mon * 3,
- (long)tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ (long)(tm.tm_year + 1900), tm.tm_hour, tm.tm_min, tm.tm_sec);
http_cmd(conn, "If-Modified-Since: %s\r\n", buf);
}
--5a4ne2b4mjjpywwl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pkgsrc.libfetch.diff"
Index: files/common.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/common.c,v
retrieving revision 1.33
diff -u -r1.33 common.c
--- files/common.c 11 Apr 2026 10:41:52 -0000 1.33
+++ files/common.c 11 Apr 2026 14:16:52 -0000
@@ -374,7 +374,9 @@
{
conn_t *conn, *last_conn = NULL;
- for (conn = connection_cache; conn; conn = conn->next_cached) {
+ for (conn = connection_cache; conn; last_conn = conn,
+ conn = conn->next_cached)
+ {
if (conn->cache_url->port == url->port &&
strcmp(conn->cache_url->scheme, url->scheme) == 0 &&
strcmp(conn->cache_url->host, url->host) == 0 &&
@@ -401,8 +403,8 @@
void
fetch_cache_put(conn_t *conn, int (*closecb)(conn_t *))
{
- conn_t *iter, *last;
- int global_count, host_count;
+ conn_t *iter, *last, *oiter;
+ int global_count, host_count, added;
if (conn->cache_url == NULL || cache_global_limit == 0) {
(*closecb)(conn);
@@ -411,20 +413,28 @@
global_count = host_count = 0;
last = NULL;
- for (iter = connection_cache; iter;
- last = iter, iter = iter->next_cached) {
+ for (iter = connection_cache; iter; ) {
++global_count;
- if (strcmp(conn->cache_url->host, iter->cache_url->host) == 0)
+ added = !strcmp(conn->cache_url->host, iter->cache_url->host);
+ if (added)
++host_count;
if (global_count < cache_global_limit &&
- host_count < cache_per_host_limit)
- continue;
- --global_count;
- if (last != NULL)
- last->next_cached = iter->next_cached;
- else
- connection_cache = iter->next_cached;
- (*iter->cache_close)(iter);
+ host_count < cache_per_host_limit) {
+ oiter = NULL;
+ last = iter;
+ } else {
+ --global_count;
+ if (added)
+ --host_count;
+ if (last != NULL)
+ last->next_cached = iter->next_cached;
+ else
+ connection_cache = iter->next_cached;
+ oiter = iter;
+ }
+ iter = iter->next_cached;
+ if (oiter)
+ (*oiter->cache_close)(oiter);
}
conn->cache_close = closecb;
@@ -631,7 +641,7 @@
return (-1);
if (len == 0)
break;
- next = memchr(conn->buf + conn->buflen, '\n', len);
+ next = memchr(conn->buf + conn->buflen, '\n', (size_t)len);
conn->buflen += len;
if (conn->buflen == conn->bufsize && next == NULL) {
tmp = conn->buf;
@@ -717,7 +727,7 @@
errno = 0;
#ifdef WITH_SSL
if (conn->ssl != NULL)
- wlen = SSL_write(conn->ssl, buf, len);
+ wlen = SSL_write(conn->ssl, buf, (int)len);
else
#endif
#ifndef MSG_NOSIGNAL
@@ -752,6 +762,22 @@
{
int ret;
+#ifdef WITH_SSL
+ if (conn->ssl) {
+ SSL_shutdown(conn->ssl);
+ SSL_set_connect_state(conn->ssl);
+ SSL_free(conn->ssl);
+ conn->ssl = NULL;
+ }
+ if (conn->ssl_ctx) {
+ SSL_CTX_free(conn->ssl_ctx);
+ conn->ssl_ctx = NULL;
+ }
+ if (conn->ssl_cert) {
+ X509_free(conn->ssl_cert);
+ conn->ssl_cert = NULL;
+ }
+#endif
ret = close(conn->sd);
if (conn->cache_url)
fetchFreeURL(conn->cache_url);
Index: files/common.h
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/common.h,v
retrieving revision 1.26
diff -u -r1.26 common.h
--- files/common.h 11 Apr 2026 10:41:52 -0000 1.26
+++ files/common.h 11 Apr 2026 14:16:52 -0000
@@ -99,7 +99,7 @@
void fetch_seterr(struct fetcherr *, int);
void fetch_syserr(void);
-void fetch_info(const char *, ...) LIBFETCH_PRINTFLIKE(1, 2);
+void fetch_info(const char *, ...) LIBFETCH_PRINTFLIKE(1, 2);
int fetch_default_port(const char *);
int fetch_default_proxy_port(const char *);
int fetch_bind(int, int, const char *);
Index: files/ftp.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/ftp.c,v
retrieving revision 1.50
diff -u -r1.50 ftp.c
--- files/ftp.c 11 Apr 2026 10:41:52 -0000 1.50
+++ files/ftp.c 11 Apr 2026 14:16:52 -0000
@@ -145,7 +145,7 @@
if (sin6->sin6_family != AF_INET6 ||
!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
return;
- sin4 = (struct sockaddr_in *)sin6;
+ sin4 = (struct sockaddr_in *)(void *)sin6;
#ifdef s6_addr32
addr = sin6->sin6_addr.s6_addr32[3];
#else
@@ -208,7 +208,7 @@
va_list ap;
size_t len;
char *msg;
- int r;
+ ssize_t r;
va_start(ap, fmt);
len = vasprintf(&msg, fmt, ap);
@@ -235,7 +235,7 @@
* Return a pointer to the filename part of a path
*/
static const char *
-ftp_filename(const char *file, int *len, int *type, int subdir)
+ftp_filename(const char *file, size_t *len, int *type, int subdir)
{
const char *s;
@@ -262,6 +262,7 @@
{
char *src, *dst, *end;
int q;
+ size_t len;
if (conn->err != FTP_WORKING_DIRECTORY &&
conn->err != FTP_FILE_ACTION_OK)
@@ -270,7 +271,8 @@
src = conn->buf + 4;
if (src >= end || *src++ != '"')
return (FTP_PROTOCOL_ERROR);
- *pwd = malloc(end - src + 1);
+ len = end - src + 1;
+ *pwd = malloc(len);
if (*pwd == NULL)
return (FTP_PROTOCOL_ERROR);
for (q = 0, dst = *pwd; src < end; ++src) {
@@ -301,7 +303,8 @@
{
const char *beg, *end;
char *pwd, *dst;
- int e, i, len;
+ int e;
+ size_t i, len;
if (*path != '/') {
ftp_seterr(501);
@@ -349,7 +352,7 @@
len = strlen(pwd);
/* Look for a common prefix between PWD and dir to fetch. */
- for (i = 0; i <= len && i <= end - dst; ++i)
+ for (i = 0; i <= len && i <= (size_t)(end - dst); ++i)
if (pwd[i] != dst[i])
break;
/* Keep going up a dir until we have a matching prefix. */
@@ -416,6 +419,7 @@
case 0:
case 's':
mode = 'S';
+ /*FALLTHROUGH*/
case 'S':
break;
default:
@@ -444,15 +448,17 @@
case 0:
case 'i':
type = 'I';
+ /*FALLTHROUGH*/
case 'I':
break;
case 'a':
type = 'A';
+ /*FALLTHROUGH*/
case 'A':
break;
case 'd':
type = 'D';
- /* FALLTHROUGH */
+ /*FALLTHROUGH*/
case 'D':
/* can't handle yet */
default:
@@ -472,7 +478,8 @@
{
char *ln;
const char *filename;
- int filenamelen, type, year;
+ size_t filenamelen;
+ int type;
struct tm tm;
time_t t;
int e;
@@ -524,13 +531,13 @@
return (-1);
}
if (sscanf(ln, "%04d%02d%02d%02d%02d%02d",
- &year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
ftp_seterr(FTP_PROTOCOL_ERROR);
return (-1);
}
tm.tm_mon--;
- tm.tm_year = year - 1900;
+ tm.tm_year -= 1900;
tm.tm_isdst = -1;
t = timegm(&tm);
if (t == (time_t)-1)
@@ -560,7 +567,7 @@
ftp_readfn(void *v, void *buf, size_t len)
{
struct ftpio *io;
- int r;
+ ssize_t r;
io = (struct ftpio *)v;
if (io == NULL) {
@@ -593,7 +600,7 @@
ftp_writefn(void *v, const void *buf, size_t len)
{
struct ftpio *io;
- int w;
+ ssize_t w;
io = (struct ftpio *)v;
if (io == NULL) {
@@ -642,7 +649,7 @@
fetch_close(io->dconn);
io->dconn = NULL;
io->dir = -1;
- ftp_chkerr(io->cconn);
+ (void)ftp_chkerr(io->cconn);
fetch_cache_put(io->cconn, ftp_disconnect);
free(io);
return;
@@ -683,7 +690,8 @@
} u;
const char *bindaddr;
const char *filename;
- int filenamelen, type;
+ size_t filenamelen;
+ int type;
int pasv, verbose;
int e, sd = -1;
socklen_t l;
@@ -765,7 +773,7 @@
}
l = (e == FTP_PASSIVE_MODE ? 6 : 21);
for (i = 0; *p && i < l; i++, p++)
- addr[i] = strtol(p, &p, 10);
+ addr[i] = (unsigned char)strtol(p, &p, 10);
if (i < l) {
e = FTP_PROTOCOL_ERROR;
goto ouch;
@@ -859,9 +867,7 @@
int low = CHECK_FLAG('l');
#endif
int d;
-#ifdef INET6
char hname[INET6_ADDRSTRLEN];
-#endif
switch (u.ss.ss_family) {
case AF_INET6:
@@ -869,7 +875,7 @@
#ifdef IPV6_PORTRANGE
arg = low ? IPV6_PORTRANGE_DEFAULT : IPV6_PORTRANGE_HIGH;
if (setsockopt(sd, IPPROTO_IPV6, IPV6_PORTRANGE,
- (char *)&arg, sizeof(arg)) == -1)
+ &arg, (socklen_t)sizeof(arg)) == -1)
goto sysouch;
#endif
break;
@@ -878,7 +884,7 @@
#ifdef IP_PORTRANGE
arg = low ? IP_PORTRANGE_DEFAULT : IP_PORTRANGE_HIGH;
if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE,
- (char *)&arg, sizeof(arg)) == -1)
+ &arg, (socklen_t)sizeof(arg)) == -1)
goto sysouch;
#endif
break;
@@ -900,14 +906,13 @@
e = ftp_cmd(conn, "PORT %d,%d,%d,%d,%d,%d\r\n",
(a >> 24) & 0xff, (a >> 16) & 0xff,
(a >> 8) & 0xff, a & 0xff,
- (p >> 8) & 0xff, p & 0xff);
+ ((unsigned int)p >> 8) & 0xff, p & 0xff);
break;
-#ifdef INET6
case AF_INET6:
e = -1;
u.sin6.sin6_scope_id = 0;
if (getnameinfo(&u.sa, l,
- hname, sizeof(hname),
+ hname, (socklen_t)sizeof(hname),
NULL, 0, NI_NUMERICHOST) == 0) {
e = ftp_cmd(conn, "EPRT |%d|%s|%d|\r\n", 2, hname,
htons(u.sin6.sin6_port));
@@ -932,7 +937,6 @@
2, port >> 8, port & 0xff);
}
break;
-#endif
default:
e = FTP_PROTOCOL_ERROR; /* XXX: error code should be prepared */
goto ouch;
@@ -1116,6 +1120,7 @@
return (NULL);
if (fetch_no_proxy_match(url->host))
return (NULL);
+
if (((p = getenv("FTP_PROXY")) || (p = getenv("ftp_proxy")) ||
(p = getenv("HTTP_PROXY")) || (p = getenv("http_proxy"))) &&
*p && (purl = fetchParseURL(p)) != NULL) {
Index: files/http.c
===================================================================
RCS file: /cvsroot/pkgsrc/net/libfetch/files/http.c,v
retrieving revision 1.45
diff -u -r1.45 http.c
--- files/http.c 11 Apr 2026 10:41:52 -0000 1.45
+++ files/http.c 11 Apr 2026 14:16:52 -0000
@@ -154,7 +154,7 @@
char *buf; /* chunk buffer */
size_t bufsize; /* size of chunk buffer */
ssize_t buflen; /* amount of data currently in buffer */
- int bufpos; /* current read offset in buffer */
+ size_t bufpos; /* current read offset in buffer */
int eof; /* end-of-file flag */
int error; /* error flag */
size_t chunksize; /* remaining size of current chunk */
@@ -164,7 +164,7 @@
/*
* Get next chunk header
*/
-static int
+static ssize_t
http_new_chunk(struct httpio *io)
{
char *p;
@@ -213,7 +213,7 @@
/*
* Fill the input buffer, do chunk decoding on the fly
*/
-static int
+static ssize_t
http_fillbuf(struct httpio *io, size_t len)
{
if (io->error)
@@ -294,7 +294,7 @@
for (pos = 0; len > 0; pos += l, len -= l) {
/* empty buffer */
- if (!io->buf || io->bufpos == io->buflen)
+ if (!io->buf || (ssize_t)io->bufpos == io->buflen)
if (http_fillbuf(io, len) < 1)
break;
l = io->buflen - io->bufpos;
@@ -333,7 +333,7 @@
val = 0;
setsockopt(io->conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
- sizeof(val));
+ (socklen_t)sizeof(val));
fetch_cache_put(io->conn, fetch_close);
#if defined(TCP_NOPUSH) && !defined(__APPLE__)
val = 1;
@@ -419,7 +419,7 @@
va_list ap;
size_t len;
char *msg;
- int r;
+ ssize_t r;
va_start(ap, fmt);
len = vasprintf(&msg, fmt, ap);
@@ -765,8 +765,15 @@
#endif
curl = (purl != NULL) ? purl : URL;
+ if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
+ URL = purl;
+ } else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
+
+ /* XXX should set an error code */
+ return (NULL);
+ }
- if ((conn = fetch_cache_get(URL, af)) != NULL) {
+ if ((conn = fetch_cache_get(curl, af)) != NULL) {
*cached = 1;
return (conn);
}
@@ -779,16 +786,18 @@
URL->host, URL->port);
http_cmd(conn, "Host: %s:%d\r\n",
URL->host, URL->port);
+ /* proxy authorization */
+ if (*purl->user || *purl->pwd)
+ http_basic_auth(conn, "Proxy-Authorization",
+ purl->user, purl->pwd);
+ else if ((p = getenv("HTTP_PROXY_AUTH")) != NULL && *p != '\0')
+ http_authorize(conn, "Proxy-Authorization", p);
http_cmd(conn, "\r\n");
if (http_get_reply(conn) != HTTP_OK) {
http_seterr(conn->err);
goto ouch;
}
/* Read and discard the rest of the proxy response */
- if (fetch_getln(conn) < 0) {
- fetch_syserr();
- goto ouch;
- }
do {
switch ((h = http_next_header(conn, &p))) {
case hdr_syserror:
@@ -1021,7 +1030,7 @@
#endif
val = 1;
setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
- sizeof(val));
+ (socklen_t)sizeof(val));
/* get reply */
switch (http_get_reply(conn)) {
--5a4ne2b4mjjpywwl--
Home |
Main Index |
Thread Index |
Old Index