pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/libfetch libfetch-2.24:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/36b53e5716ac
branches:  trunk
changeset: 397636:36b53e5716ac
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Aug 16 20:31:29 2009 +0000

description:
libfetch-2.24:
Fix a bug in the line reading optimisation, which could get confused if
the byte following the new line is a NUL. Adresses Arch Linux problem
report #15845.

Do not reuse a FTP connection if there is currently a transfer active.
Some FTP servers hang on the NOOP command. Reported by Manuel Bouyer.

diffstat:

 net/libfetch/Makefile       |   4 ++--
 net/libfetch/files/common.c |  25 ++++++++++++++++++-------
 net/libfetch/files/common.h |   3 ++-
 net/libfetch/files/ftp.c    |   5 ++++-
 4 files changed, 26 insertions(+), 11 deletions(-)

diffs (138 lines):

diff -r 4d90dee4275d -r 36b53e5716ac net/libfetch/Makefile
--- a/net/libfetch/Makefile     Sun Aug 16 20:21:47 2009 +0000
+++ b/net/libfetch/Makefile     Sun Aug 16 20:31:29 2009 +0000
@@ -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 -r 4d90dee4275d -r 36b53e5716ac net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Sun Aug 16 20:21:47 2009 +0000
+++ b/net/libfetch/files/common.c       Sun Aug 16 20:31:29 2009 +0000
@@ -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@localhost>
@@ -237,6 +237,7 @@
        conn->next_buf = NULL;
        conn->next_len = 0;
        conn->sd = sd;
+       conn->is_active = 0;
        ++conn->ref;
        return (conn);
 }
@@ -475,18 +476,22 @@
        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 @@
                        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 @@
        } 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 -r 4d90dee4275d -r 36b53e5716ac net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Sun Aug 16 20:21:47 2009 +0000
+++ b/net/libfetch/files/common.h       Sun Aug 16 20:31:29 2009 +0000
@@ -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 @@
 #  endif
 #endif
        int              ref;           /* reference count */
+       int              is_active;
 };
 
 /* Structure used for error message lists */
diff -r 4d90dee4275d -r 36b53e5716ac net/libfetch/files/ftp.c
--- a/net/libfetch/files/ftp.c  Sun Aug 16 20:21:47 2009 +0000
+++ b/net/libfetch/files/ftp.c  Sun Aug 16 20:31:29 2009 +0000
@@ -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@localhost>
@@ -584,6 +584,7 @@
        }
        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 @@
        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 @@
 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)



Home | Main Index | Thread Index | Old Index