summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--net/libfetch/Makefile4
-rw-r--r--net/libfetch/files/common.c25
-rw-r--r--net/libfetch/files/common.h3
-rw-r--r--net/libfetch/files/ftp.c5
4 files changed, 26 insertions, 11 deletions
diff --git a/net/libfetch/Makefile b/net/libfetch/Makefile
index 347b53c9c1e..66561e2b28e 100644
--- a/net/libfetch/Makefile
+++ b/net/libfetch/Makefile
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.31 2009/08/11 21:03:56 hasso Exp $
+# $NetBSD: Makefile,v 1.32 2009/08/16 20:31:29 joerg Exp $
#
-DISTNAME= libfetch-2.24
+DISTNAME= libfetch-2.25
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/net/libfetch/files/common.c b/net/libfetch/files/common.c
index c9a55ee4119..39e3adb1cf3 100644
--- a/net/libfetch/files/common.c
+++ b/net/libfetch/files/common.c
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.19 2009/08/11 20:48:06 joerg Exp $ */
+/* $NetBSD: common.c,v 1.20 2009/08/16 20:31:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -237,6 +237,7 @@ fetch_reopen(int sd)
conn->next_buf = NULL;
conn->next_len = 0;
conn->sd = sd;
+ conn->is_active = 0;
++conn->ref;
return (conn);
}
@@ -475,18 +476,22 @@ fetch_getln(conn_t *conn)
ssize_t len;
if (conn->buf == NULL) {
- if ((conn->buf = malloc(MIN_BUF_SIZE + 1)) == NULL) {
+ if ((conn->buf = malloc(MIN_BUF_SIZE)) == NULL) {
errno = ENOMEM;
return (-1);
}
conn->bufsize = MIN_BUF_SIZE;
}
- conn->buf[0] = '\0';
conn->buflen = 0;
next = NULL;
do {
+ /*
+ * conn->bufsize != conn->buflen at this point,
+ * so the buffer can be NUL-terminated below for
+ * the case of len == 0.
+ */
len = fetch_read(conn, conn->buf + conn->buflen,
conn->bufsize - conn->buflen);
if (len == -1)
@@ -495,10 +500,13 @@ fetch_getln(conn_t *conn)
break;
next = memchr(conn->buf + conn->buflen, '\n', len);
conn->buflen += len;
- if (conn->buflen == conn->bufsize &&
- (next == NULL || next[1] == '\0')) {
+ if (conn->buflen == conn->bufsize && next == NULL) {
tmp = conn->buf;
- tmpsize = conn->bufsize * 2 + 1;
+ tmpsize = conn->bufsize * 2;
+ if (tmpsize < conn->bufsize) {
+ errno = ENOMEM;
+ return (-1);
+ }
if ((tmp = realloc(tmp, tmpsize)) == NULL) {
errno = ENOMEM;
return (-1);
@@ -509,11 +517,14 @@ fetch_getln(conn_t *conn)
} while (next == NULL);
if (next != NULL) {
+ *next = '\0';
conn->next_buf = next + 1;
conn->next_len = conn->buflen - (conn->next_buf - conn->buf);
conn->buflen = next - conn->buf;
+ } else {
+ conn->buf[conn->buflen] = '\0';
+ conn->next_len = 0;
}
- conn->buf[conn->buflen] = '\0';
return (0);
}
diff --git a/net/libfetch/files/common.h b/net/libfetch/files/common.h
index cbe4c70a757..876d68f0afd 100644
--- a/net/libfetch/files/common.h
+++ b/net/libfetch/files/common.h
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.11 2009/03/05 19:08:47 abs Exp $ */
+/* $NetBSD: common.h,v 1.12 2009/08/16 20:31:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -72,6 +72,7 @@ struct fetchconn {
# endif
#endif
int ref; /* reference count */
+ int is_active;
};
/* Structure used for error message lists */
diff --git a/net/libfetch/files/ftp.c b/net/libfetch/files/ftp.c
index 9c33d779ec0..499f0c0d450 100644
--- a/net/libfetch/files/ftp.c
+++ b/net/libfetch/files/ftp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.28 2009/08/06 14:02:38 tnn Exp $ */
+/* $NetBSD: ftp.c,v 1.29 2009/08/16 20:31:29 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>
@@ -584,6 +584,7 @@ ftp_closefn(void *v)
}
fetch_close(io->dconn);
io->dir = -1;
+ io->dconn->is_active = 0;
io->dconn = NULL;
r = ftp_chkerr(io->cconn);
if (io->cconn == cached_connection && io->cconn->ref == 1)
@@ -607,6 +608,7 @@ ftp_setup(conn_t *cconn, conn_t *dconn, int mode)
io->dconn = dconn;
io->dir = mode;
io->eof = io->err = 0;
+ io->cconn->is_active = 1;
f = fetchIO_unopen(io, ftp_readfn, ftp_writefn, ftp_closefn);
if (f == NULL)
free(io);
@@ -1048,6 +1050,7 @@ static int
ftp_isconnected(struct url *url)
{
return (cached_connection
+ && (cached_connection->is_active == 0)
&& (strcmp(url->host, cached_host.host) == 0)
&& (strcmp(url->user, cached_host.user) == 0)
&& (strcmp(url->pwd, cached_host.pwd) == 0)