Source-Changes-HG archive

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

[src/netbsd-7]: src/usr.bin/ftp Pull up following revision(s) (requested by n...



details:   https://anonhg.NetBSD.org/src/rev/c43af2bd82dc
branches:  netbsd-7
changeset: 799861:c43af2bd82dc
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 13 11:49:14 2016 +0000

description:
Pull up following revision(s) (requested by nonakap in ticket #1133):
        usr.bin/ftp/fetch.c: revision 1.208-1.221
        usr.bin/ftp/cmds.c: revision 1.136-1.137
        usr.bin/ftp/ssl.c: revision 1.5
        usr.bin/ftp/ftp.c: revision 1.165-1.166
        usr.bin/ftp/ftp_var.h: revision 1.84

Workaround const issues of SSL_set_tlsext_host_name.

Use the proper format "[IPv6 address]:port" when reporting connection
attempts to IPv6 endpoints.

(Hopefully) fix build without IPv6 support

Try to factor out some code, this is completely out of control.

Separate no_proxy handling.

Factor the proxy handling code out.

Fix compile failure without WITH_SSL.

PR/50438: NONAKA Kimihiro: ftp(1): CONNECT method support

make DPRINTF/DWARN always statements.

Fix to connect https via proxy.

Fix ttyout message.

Simplify and factor out connect message

Split the position/size parsing into a separate function.

Mark function as only needed with ssl.

Fix downloads of local files using file:// URLs

Initialize the token match pointer.

use sizeof() and array notation.
CID 1354295: Array overrun.

diffstat:

 usr.bin/ftp/cmds.c    |    12 +-
 usr.bin/ftp/fetch.c   |  1549 +++++++++++++++++++++++++++++-------------------
 usr.bin/ftp/ftp.c     |    16 +-
 usr.bin/ftp/ftp_var.h |    11 +-
 usr.bin/ftp/ssl.c     |     6 +-
 5 files changed, 965 insertions(+), 629 deletions(-)

diffs (truncated from 2088 to 300 lines):

diff -r c0027ffe481e -r c43af2bd82dc usr.bin/ftp/cmds.c
--- a/usr.bin/ftp/cmds.c        Sun Mar 13 08:07:53 2016 +0000
+++ b/usr.bin/ftp/cmds.c        Sun Mar 13 11:49:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos Exp $      */
+/*     $NetBSD: cmds.c,v 1.135.8.1 2016/03/13 11:49:14 martin Exp $    */
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.135 2012/12/22 16:57:09 christos Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.135.8.1 2016/03/13 11:49:14 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -1967,15 +1967,15 @@
        char *cp2 = dst;
        size_t i, ostop;
 
-       for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
+       for (ostop = 0; ntout[ostop] && ostop < sizeof(ntout); ostop++)
                continue;
        for (cp1 = src; *cp1; cp1++) {
                int found = 0;
-               for (i = 0; *(ntin + i) && i < 16; i++) {
-                       if (*cp1 == *(ntin + i)) {
+               for (i = 0; i < sizeof(ntin) && ntin[i]; i++) {
+                       if (*cp1 == ntin[i]) {
                                found++;
                                if (i < ostop) {
-                                       *cp2++ = *(ntout + i);
+                                       *cp2++ = ntout[i];
                                        if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
                                                goto out;
                                }
diff -r c0027ffe481e -r c43af2bd82dc usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Sun Mar 13 08:07:53 2016 +0000
+++ b/usr.bin/ftp/fetch.c       Sun Mar 13 11:49:14 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.205.4.2 2015/11/05 05:26:38 riz Exp $      */
+/*     $NetBSD: fetch.c,v 1.205.4.3 2016/03/13 11:49:14 martin Exp $   */
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.205.4.2 2015/11/05 05:26:38 riz Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.205.4.3 2016/03/13 11:49:14 martin Exp $");
 #endif /* not lint */
 
 /*
@@ -74,27 +74,47 @@
 typedef enum {
        UNKNOWN_URL_T=-1,
        HTTP_URL_T,
-#ifdef WITH_SSL
        HTTPS_URL_T,
-#endif
        FTP_URL_T,
        FILE_URL_T,
        CLASSIC_URL_T
 } url_t;
 
+struct authinfo {
+       char *auth;
+       char *user;
+       char *pass;
+};
+
+struct urlinfo {
+       char *host;
+       char *port;
+       char *path;
+       url_t utype;
+       in_port_t portnum;
+};
+
+struct posinfo {
+       off_t rangestart;
+       off_t rangeend;
+       off_t entitylen;
+};
+
 __dead static void     aborthttp(int);
 __dead static void     timeouthttp(int);
 #ifndef NO_AUTH
-static int     auth_url(const char *, char **, const char *, const char *);
+static int     auth_url(const char *, char **, const struct authinfo *);
 static void    base64_encode(const unsigned char *, size_t, unsigned char *);
 #endif
 static int     go_fetch(const char *);
 static int     fetch_ftp(const char *);
 static int     fetch_url(const char *, const char *, char *, char *);
 static const char *match_token(const char **, const char *);
-static int     parse_url(const char *, const char *, url_t *, char **,
-                           char **, char **, char **, in_port_t *, char **);
+static int     parse_url(const char *, const char *, struct urlinfo *,
+    struct authinfo *);
 static void    url_decode(char *);
+static void    freeauthinfo(struct authinfo *);
+static void    freeurlinfo(struct urlinfo *);
 
 static int     redirect_loop;
 
@@ -146,6 +166,54 @@
        return orig;
 }
 
+static void
+initposinfo(struct posinfo *pi)
+{
+       pi->rangestart = pi->rangeend = pi->entitylen = -1;
+}
+
+static void
+initauthinfo(struct authinfo *ai, char *auth)
+{
+       ai->auth = auth;
+       ai->user = ai->pass = 0;
+}
+
+static void
+freeauthinfo(struct authinfo *a)
+{
+       FREEPTR(a->user);
+       if (a->pass != NULL)
+               memset(a->pass, 0, strlen(a->pass));
+       FREEPTR(a->pass);
+}
+
+static void
+initurlinfo(struct urlinfo *ui)
+{
+       ui->host = ui->port = ui->path = 0;
+       ui->utype = UNKNOWN_URL_T;
+       ui->portnum = 0;
+}
+
+static void
+copyurlinfo(struct urlinfo *dui, struct urlinfo *sui)
+{
+       dui->host = ftp_strdup(sui->host);
+       dui->port = ftp_strdup(sui->port);
+       dui->path = ftp_strdup(sui->path);
+       dui->utype = sui->utype;
+       dui->portnum = sui->portnum;
+}
+
+static void
+freeurlinfo(struct urlinfo *ui)
+{
+       FREEPTR(ui->host);
+       FREEPTR(ui->port);
+       FREEPTR(ui->path);
+}
+
 #ifndef NO_AUTH
 /*
  * Generate authorization response based on given authentication challenge.
@@ -153,8 +221,7 @@
  * Sets response to a malloc(3)ed string; caller should free.
  */
 static int
-auth_url(const char *challenge, char **response, const char *guser,
-       const char *gpass)
+auth_url(const char *challenge, char **response, const struct authinfo *auth)
 {
        const char      *cp, *scheme, *errormsg;
        char            *ep, *clear, *realm;
@@ -198,8 +265,8 @@
        }
 
        fprintf(ttyout, "Username for `%s': ", realm);
-       if (guser != NULL) {
-               (void)strlcpy(uuser, guser, sizeof(uuser));
+       if (auth->user != NULL) {
+               (void)strlcpy(uuser, auth->user, sizeof(uuser));
                fprintf(ttyout, "%s\n", uuser);
        } else {
                (void)fflush(ttyout);
@@ -208,8 +275,8 @@
                        goto cleanup_auth_url;
                }
        }
-       if (gpass != NULL)
-               upass = gpass;
+       if (auth->pass != NULL)
+               upass = auth->pass;
        else {
                gotpass = getpass("Password: ");
                if (gotpass == NULL) {
@@ -229,7 +296,7 @@
 
                                                /* scheme + " " + enc + "\0" */
        rlen = strlen(scheme) + 1 + (clen + 2) * 4 / 3 + 1;
-       *response = (char *)ftp_malloc(rlen);
+       *response = ftp_malloc(rlen);
        (void)strlcpy(*response, scheme, rlen);
        len = strlcat(*response, " ", rlen);
                        /* use  `clen - 1'  to not encode the trailing NUL */
@@ -328,57 +395,48 @@
  *     "ftp://host/dir/file";           "dir/file"
  *     "ftp://host//dir/file";          "/dir/file"
  */
+
 static int
-parse_url(const char *url, const char *desc, url_t *utype,
-               char **uuser, char **pass, char **host, char **port,
-               in_port_t *portnum, char **path)
+parse_url(const char *url, const char *desc, struct urlinfo *ui,
+    struct authinfo *auth) 
 {
        const char      *origurl, *tport;
        char            *cp, *ep, *thost;
        size_t           len;
 
-       if (url == NULL || desc == NULL || utype == NULL || uuser == NULL
-           || pass == NULL || host == NULL || port == NULL || portnum == NULL
-           || path == NULL)
+       if (url == NULL || desc == NULL || ui == NULL || auth == NULL)
                errx(1, "parse_url: invoked with NULL argument!");
        DPRINTF("parse_url: %s `%s'\n", desc, url);
 
        origurl = url;
-       *utype = UNKNOWN_URL_T;
-       *uuser = *pass = *host = *port = *path = NULL;
-       *portnum = 0;
        tport = NULL;
 
        if (STRNEQUAL(url, HTTP_URL)) {
                url += sizeof(HTTP_URL) - 1;
-               *utype = HTTP_URL_T;
-               *portnum = HTTP_PORT;
+               ui->utype = HTTP_URL_T;
+               ui->portnum = HTTP_PORT;
                tport = httpport;
        } else if (STRNEQUAL(url, FTP_URL)) {
                url += sizeof(FTP_URL) - 1;
-               *utype = FTP_URL_T;
-               *portnum = FTP_PORT;
+               ui->utype = FTP_URL_T;
+               ui->portnum = FTP_PORT;
                tport = ftpport;
        } else if (STRNEQUAL(url, FILE_URL)) {
                url += sizeof(FILE_URL) - 1;
-               *utype = FILE_URL_T;
+               ui->utype = FILE_URL_T;
+               tport = "";
 #ifdef WITH_SSL
        } else if (STRNEQUAL(url, HTTPS_URL)) {
                url += sizeof(HTTPS_URL) - 1;
-               *utype = HTTPS_URL_T;
-               *portnum = HTTPS_PORT;
+               ui->utype = HTTPS_URL_T;
+               ui->portnum = HTTPS_PORT;
                tport = httpsport;
 #endif
        } else {
                warnx("Invalid %s `%s'", desc, url);
  cleanup_parse_url:
-               FREEPTR(*uuser);
-               if (*pass != NULL)
-                       memset(*pass, 0, strlen(*pass));
-               FREEPTR(*pass);
-               FREEPTR(*host);
-               FREEPTR(*port);
-               FREEPTR(*path);
+               freeauthinfo(auth);
+               freeurlinfo(ui);
                return (-1);
        }
 
@@ -393,26 +451,26 @@
                len = ep - url;
                thost = (char *)ftp_malloc(len + 1);
                (void)strlcpy(thost, url, len + 1);
-               if (*utype == FTP_URL_T)        /* skip first / for ftp URLs */
+               if (ui->utype == FTP_URL_T)     /* skip first / for ftp URLs */
                        ep++;
-               *path = ftp_strdup(ep);
+               ui->path = ftp_strdup(ep);
        }
 
        cp = strchr(thost, '@');        /* look for user[:pass]@ in URLs */
        if (cp != NULL) {
-               if (*utype == FTP_URL_T)
+               if (ui->utype == FTP_URL_T)
                        anonftp = 0;    /* disable anonftp */
-               *uuser = thost;
+               auth->user = thost;
                *cp = '\0';
                thost = ftp_strdup(cp + 1);
-               cp = strchr(*uuser, ':');
+               cp = strchr(auth->user, ':');
                if (cp != NULL) {



Home | Main Index | Thread Index | Old Index