From d91fa42bf7bb6d01a1ff92439f18aeda06978985 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 5 Nov 2012 10:45:37 +0000 Subject: [PATCH] MFH r225813, r233648: man page fixes MFH r234837: avoid busy-loop on slow connections MFH r234838: don't reuse credentials when redirected to another host MFH r240496: use libmd if and only if OpenSSL is not available git-svn-id: svn://svn.freebsd.org/base/stable/8@242607 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libfetch/Makefile | 4 ++-- lib/libfetch/common.c | 30 +++++++++++++----------------- lib/libfetch/fetch.3 | 4 ++-- lib/libfetch/http.c | 12 +++++++++++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/libfetch/Makefile b/lib/libfetch/Makefile index 7b29aa2df..085aba2c6 100644 --- a/lib/libfetch/Makefile +++ b/lib/libfetch/Makefile @@ -16,8 +16,8 @@ CFLAGS+= -DINET6 .if ${MK_OPENSSL} != "no" CFLAGS+= -DWITH_SSL -DPADD= ${LIBSSL} ${LIBCRYPTO} ${LIBMD} -LDADD= -lssl -lcrypto -lmd +DPADD= ${LIBSSL} ${LIBCRYPTO} +LDADD= -lssl -lcrypto .else DPADD= ${LIBMD} LDADD= -lmd diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index e55459c54..967a708a2 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -458,11 +458,9 @@ fetch_read(conn_t *conn, char *buf, size_t len) struct timeval now, timeout, delta; fd_set readfds; ssize_t rlen, total; - int r; char *start; - if (fetchTimeout) { - FD_ZERO(&readfds); + if (fetchTimeout > 0) { gettimeofday(&timeout, NULL); timeout.tv_sec += fetchTimeout; } @@ -526,23 +524,21 @@ fetch_read(conn_t *conn, char *buf, size_t len) return (-1); } // assert(rlen == FETCH_READ_WAIT); - while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) { + FD_ZERO(&readfds); + while (!FD_ISSET(conn->sd, &readfds)) { FD_SET(conn->sd, &readfds); - gettimeofday(&now, NULL); - delta.tv_sec = timeout.tv_sec - now.tv_sec; - delta.tv_usec = timeout.tv_usec - now.tv_usec; - if (delta.tv_usec < 0) { - delta.tv_usec += 1000000; - delta.tv_sec--; - } - if (delta.tv_sec < 0) { - errno = ETIMEDOUT; - fetch_syserr(); - return (-1); + if (fetchTimeout > 0) { + gettimeofday(&now, NULL); + if (!timercmp(&timeout, &now, >)) { + errno = ETIMEDOUT; + fetch_syserr(); + return (-1); + } + timersub(&timeout, &now, &delta); } errno = 0; - r = select(conn->sd + 1, &readfds, NULL, NULL, &delta); - if (r == -1) { + if (select(conn->sd + 1, &readfds, NULL, NULL, + fetchTimeout > 0 ? &delta : NULL) < 0) { if (errno == EINTR) { if (fetchRestartCalls) continue; diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3 index 1d60b4df5..bdca63e68 100644 --- a/lib/libfetch/fetch.3 +++ b/lib/libfetch/fetch.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 26, 2010 +.Dd September 27, 2011 .Dt FETCH 3 .Os .Sh NAME @@ -365,7 +365,7 @@ If the (if-modified-since) flag is specified, and the .Va ims_time -field is set in +field is set in .Vt "struct url" , then .Fn fetchXGetHTTP diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index d388c7e08..00dd887cf 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -76,7 +76,15 @@ __FBSDID("$FreeBSD$"); #include #include #include + +#ifdef WITH_SSL +#include +#define MD5Init(c) MD5_Init(c) +#define MD5Update(c, data, len) MD5_Update(c, data, len) +#define MD5Final(md, c) MD5_Final(md, c) +#else #include +#endif #include #include @@ -1793,7 +1801,9 @@ http_request(struct url *URL, const char *op, struct url_stat *us, DEBUG(fprintf(stderr, "failed to parse new URL\n")); goto ouch; } - if (!*new->user && !*new->pwd) { + + /* Only copy credentials if the host matches */ + if (!strcmp(new->host, url->host) && !*new->user && !*new->pwd) { strcpy(new->user, url->user); strcpy(new->pwd, url->pwd); } -- 2.45.0