Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Nov 2012 10:45:38 +0000 (UTC)
From:      Dag-Erling Smørgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r242607 - stable/8/lib/libfetch
Message-ID:  <201211051045.qA5Ajc9q082307@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Mon Nov  5 10:45:37 2012
New Revision: 242607
URL: http://svnweb.freebsd.org/changeset/base/242607

Log:
  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

Modified:
  stable/8/lib/libfetch/Makefile
  stable/8/lib/libfetch/common.c
  stable/8/lib/libfetch/fetch.3
  stable/8/lib/libfetch/http.c
Directory Properties:
  stable/8/lib/libfetch/   (props changed)

Modified: stable/8/lib/libfetch/Makefile
==============================================================================
--- stable/8/lib/libfetch/Makefile	Mon Nov  5 10:42:31 2012	(r242606)
+++ stable/8/lib/libfetch/Makefile	Mon Nov  5 10:45:37 2012	(r242607)
@@ -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

Modified: stable/8/lib/libfetch/common.c
==============================================================================
--- stable/8/lib/libfetch/common.c	Mon Nov  5 10:42:31 2012	(r242606)
+++ stable/8/lib/libfetch/common.c	Mon Nov  5 10:45:37 2012	(r242607)
@@ -458,11 +458,9 @@ fetch_read(conn_t *conn, char *buf, size
 	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
 			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;

Modified: stable/8/lib/libfetch/fetch.3
==============================================================================
--- stable/8/lib/libfetch/fetch.3	Mon Nov  5 10:42:31 2012	(r242606)
+++ stable/8/lib/libfetch/fetch.3	Mon Nov  5 10:45:37 2012	(r242607)
@@ -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

Modified: stable/8/lib/libfetch/http.c
==============================================================================
--- stable/8/lib/libfetch/http.c	Mon Nov  5 10:42:31 2012	(r242606)
+++ stable/8/lib/libfetch/http.c	Mon Nov  5 10:45:37 2012	(r242607)
@@ -76,7 +76,15 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+
+#ifdef WITH_SSL
+#include <openssl/md5.h>
+#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 <md5.h>
+#endif
 
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -1793,7 +1801,9 @@ http_request(struct url *URL, const char
 					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);
 				}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211051045.qA5Ajc9q082307>