diff options
| author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2012-05-26 17:08:01 +0000 |
|---|---|---|
| committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2012-05-26 17:08:01 +0000 |
| commit | 75e78bfdd64ad4f3a5c370b15c42817456638d37 (patch) | |
| tree | d0b9725a352e5e20345eed73ba11079a011f4cd0 | |
| parent | b1d8490434cae721f4a344876b5b66407683a8e9 (diff) | |
Notes
| -rw-r--r-- | lib/libfetch/common.c | 30 | ||||
| -rw-r--r-- | lib/libfetch/http.c | 4 |
2 files changed, 16 insertions, 18 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index e6f67c30a37cc..39a8a6b20af5c 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -455,11 +455,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; } @@ -523,23 +521,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/http.c b/lib/libfetch/http.c index 557ff26ebf941..f6e063aa71214 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -1779,7 +1779,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); } |
