On Tue, Nov 05, 2013 at 02:18:08PM +0100, Ingo Schwarze wrote:
> Hi Stefan,
> 
> Stefan Sperling wrote on Tue, Nov 05, 2013 at 01:56:33PM +0100:
> 
> > Do others think this useful? I hit this because I made copy/paste errors.
> 
> Useful?  I don't know.  Maybe, maybe not.
> 
> But your patch is NOT OK.
> 
> Try stuff like
> 
>   $ ftp '  foo' bar
> 
> I would be surprised if you couldn't get it to segfault.
> 
>   1081:  url = strdup(argv[argpos]);
>   1086:  url++;
>   1073:  free(url);
> 
> is not a great idiom, imho.

Ooops, thanks! Here's a fixed version.

Index: fetch.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.110
diff -u -p -r1.110 fetch.c
--- fetch.c     27 Oct 2013 18:31:24 -0000      1.110
+++ fetch.c     5 Nov 2013 13:32:53 -0000
@@ -1044,7 +1044,7 @@ int
 auto_fetch(int argc, char *argv[], char *outfile)
 {
        char *xargv[5];
-       char *cp, *url, *host, *dir, *file, *portnum;
+       char *cp, *url, *scheme, *host, *dir, *file, *portnum;
        char *username, *pass, *pathstart;
        char *ftpproxy, *httpproxy;
        int rval, xargc;
@@ -1073,7 +1073,7 @@ auto_fetch(int argc, char *argv[], char 
        for (rval = 0; (rval == 0) && (argpos < argc); free(url), argpos++) {
                if (strchr(argv[argpos], ':') == NULL)
                        break;
-               host = dir = file = portnum = username = pass = NULL;
+               scheme = host = dir = file = portnum = username = pass = NULL;
 
                /*
                 * We muck with the string, so we make a copy.
@@ -1085,14 +1085,17 @@ auto_fetch(int argc, char *argv[], char 
                /*
                 * Try HTTP URL-style arguments first.
                 */
-               if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 ||
+               scheme = url;
+               while (isspace(*scheme))
+                       scheme++;
+               if (strncasecmp(scheme, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 ||
 #ifndef SMALL
                    /* even if we compiled without SSL, url_get will check */
-                   strncasecmp(url, HTTPS_URL, sizeof(HTTPS_URL) -1) == 0 ||
+                   strncasecmp(scheme, HTTPS_URL, sizeof(HTTPS_URL) -1) == 0 ||
 #endif /* !SMALL */
-                   strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
+                   strncasecmp(scheme, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
                        redirect_loop = 0;
-                       if (url_get(url, httpproxy, outfile) == -1)
+                       if (url_get(scheme, httpproxy, outfile) == -1)
                                rval = argpos + 1;
                        continue;
                }

Reply via email to