Sat Nov 25 15:39:18 2017 UTC ()
Make outfile always allocated, free it to set it to NULL, and don't move it
around.


(christos)
diff -r1.228 -r1.229 src/usr.bin/ftp/fetch.c
diff -r1.123 -r1.124 src/usr.bin/ftp/main.c

cvs diff -r1.228 -r1.229 src/usr.bin/ftp/fetch.c (expand / switch to unified diff)

--- src/usr.bin/ftp/fetch.c 2017/02/15 11:52:11 1.228
+++ src/usr.bin/ftp/fetch.c 2017/11/25 15:39:17 1.229
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $ */ 1/* $NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2015 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Luke Mewburn. 8 * by Luke Mewburn.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Scott Aaron Bamford. 11 * by Scott Aaron Bamford.
12 * 12 *
13 * This code is derived from software contributed to The NetBSD Foundation 13 * This code is derived from software contributed to The NetBSD Foundation
14 * by Thomas Klausner. 14 * by Thomas Klausner.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#ifndef lint 39#ifndef lint
40__RCSID("$NetBSD: fetch.c,v 1.228 2017/02/15 11:52:11 nonaka Exp $"); 40__RCSID("$NetBSD: fetch.c,v 1.229 2017/11/25 15:39:17 christos Exp $");
41#endif /* not lint */ 41#endif /* not lint */
42 42
43/* 43/*
44 * FTP User Program -- Command line file retrieval 44 * FTP User Program -- Command line file retrieval
45 */ 45 */
46 46
47#include <sys/types.h> 47#include <sys/types.h>
48#include <sys/param.h> 48#include <sys/param.h>
49#include <sys/socket.h> 49#include <sys/socket.h>
50#include <sys/stat.h> 50#include <sys/stat.h>
51#include <sys/time.h> 51#include <sys/time.h>
52 52
53#include <netinet/in.h> 53#include <netinet/in.h>
@@ -2087,34 +2087,35 @@ fetch_ftp(const char *url) @@ -2087,34 +2087,35 @@ fetch_ftp(const char *url)
2087 if (dirhasglob || filehasglob) { 2087 if (dirhasglob || filehasglob) {
2088 int ointeractive; 2088 int ointeractive;
2089 2089
2090 ointeractive = interactive; 2090 ointeractive = interactive;
2091 interactive = 0; 2091 interactive = 0;
2092 if (restartautofetch) 2092 if (restartautofetch)
2093 (void)strlcpy(cmdbuf, "mreget", sizeof(cmdbuf)); 2093 (void)strlcpy(cmdbuf, "mreget", sizeof(cmdbuf));
2094 else 2094 else
2095 (void)strlcpy(cmdbuf, "mget", sizeof(cmdbuf)); 2095 (void)strlcpy(cmdbuf, "mget", sizeof(cmdbuf));
2096 xargv[0] = cmdbuf; 2096 xargv[0] = cmdbuf;
2097 mget(xargc, xargv); 2097 mget(xargc, xargv);
2098 interactive = ointeractive; 2098 interactive = ointeractive;
2099 } else { 2099 } else {
2100 if (outfile == NULL) { 2100 char *destfile = outfile;
 2101 if (destfile == NULL) {
2101 cp = strrchr(file, '/'); /* find savefile */ 2102 cp = strrchr(file, '/'); /* find savefile */
2102 if (cp != NULL) 2103 if (cp != NULL)
2103 outfile = cp + 1; 2104 destfile = cp + 1;
2104 else 2105 else
2105 outfile = file; 2106 destfile = file;
2106 } 2107 }
2107 xargv[2] = (char *)outfile; 2108 xargv[2] = (char *)destfile;
2108 xargv[3] = NULL; 2109 xargv[3] = NULL;
2109 xargc++; 2110 xargc++;
2110 if (restartautofetch) 2111 if (restartautofetch)
2111 reget(xargc, xargv); 2112 reget(xargc, xargv);
2112 else 2113 else
2113 get(xargc, xargv); 2114 get(xargc, xargv);
2114 } 2115 }
2115 2116
2116 if ((code / 100) == COMPLETE) 2117 if ((code / 100) == COMPLETE)
2117 rval = 0; 2118 rval = 0;
2118 2119
2119 cleanup_fetch_ftp: 2120 cleanup_fetch_ftp:
2120 freeurlinfo(&ui); 2121 freeurlinfo(&ui);
@@ -2240,28 +2241,29 @@ auto_fetch(int argc, char *argv[]) @@ -2240,28 +2241,29 @@ auto_fetch(int argc, char *argv[])
2240 (void)xsignal(SIGPIPE, lostpeer); 2241 (void)xsignal(SIGPIPE, lostpeer);
2241 2242
2242 /* 2243 /*
2243 * Loop through as long as there's files to fetch. 2244 * Loop through as long as there's files to fetch.
2244 */ 2245 */
2245 for (; (rval == 0) && (argpos < argc); argpos++) { 2246 for (; (rval == 0) && (argpos < argc); argpos++) {
2246 if (strchr(argv[argpos], ':') == NULL) 2247 if (strchr(argv[argpos], ':') == NULL)
2247 break; 2248 break;
2248 redirect_loop = 0; 2249 redirect_loop = 0;
2249 if (!anonftp) 2250 if (!anonftp)
2250 anonftp = 2; /* Handle "automatic" transfers. */ 2251 anonftp = 2; /* Handle "automatic" transfers. */
2251 rval = go_fetch(argv[argpos]); 2252 rval = go_fetch(argv[argpos]);
2252 if (outfile != NULL && strcmp(outfile, "-") != 0 2253 if (outfile != NULL && strcmp(outfile, "-") != 0
2253 && outfile[0] != '|') 2254 && outfile[0] != '|') {
2254 outfile = NULL; 2255 FREEPTR(outfile);
 2256 }
2255 if (rval > 0) 2257 if (rval > 0)
2256 rval = argpos + 1; 2258 rval = argpos + 1;
2257 } 2259 }
2258 2260
2259 if (connected && rval != -1) 2261 if (connected && rval != -1)
2260 disconnect(0, NULL); 2262 disconnect(0, NULL);
2261 return (rval); 2263 return (rval);
2262} 2264}
2263 2265
2264 2266
2265/* 2267/*
2266 * Upload multiple files from the command line. 2268 * Upload multiple files from the command line.
2267 * 2269 *

cvs diff -r1.123 -r1.124 src/usr.bin/ftp/main.c (expand / switch to unified diff)

--- src/usr.bin/ftp/main.c 2015/04/23 23:31:23 1.123
+++ src/usr.bin/ftp/main.c 2017/11/25 15:39:17 1.124
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.123 2015/04/23 23:31:23 lukem Exp $ */ 1/* $NetBSD: main.c,v 1.124 2017/11/25 15:39:17 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996-2015 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996-2015 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Luke Mewburn. 8 * by Luke Mewburn.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -88,27 +88,27 @@ @@ -88,27 +88,27 @@
88 */ 88 */
89 89
90#include <sys/cdefs.h> 90#include <sys/cdefs.h>
91#ifndef lint 91#ifndef lint
92__COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\ 92__COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\
93 The Regents of the University of California. All rights reserved.\ 93 The Regents of the University of California. All rights reserved.\
94 Copyright 1996-2015 The NetBSD Foundation, Inc. All rights reserved"); 94 Copyright 1996-2015 The NetBSD Foundation, Inc. All rights reserved");
95#endif /* not lint */ 95#endif /* not lint */
96 96
97#ifndef lint 97#ifndef lint
98#if 0 98#if 0
99static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; 99static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
100#else 100#else
101__RCSID("$NetBSD: main.c,v 1.123 2015/04/23 23:31:23 lukem Exp $"); 101__RCSID("$NetBSD: main.c,v 1.124 2017/11/25 15:39:17 christos Exp $");
102#endif 102#endif
103#endif /* not lint */ 103#endif /* not lint */
104 104
105/* 105/*
106 * FTP User Program -- Command Interface. 106 * FTP User Program -- Command Interface.
107 */ 107 */
108#include <sys/types.h> 108#include <sys/types.h>
109#include <sys/socket.h> 109#include <sys/socket.h>
110 110
111#include <err.h> 111#include <err.h>
112#include <errno.h> 112#include <errno.h>
113#include <netdb.h> 113#include <netdb.h>
114#include <paths.h> 114#include <paths.h>
@@ -314,27 +314,27 @@ main(int volatile argc, char **volatile  @@ -314,27 +314,27 @@ main(int volatile argc, char **volatile
314 314
315 case 'n': 315 case 'n':
316 autologin = 0; 316 autologin = 0;
317 break; 317 break;
318 318
319 case 'N': 319 case 'N':
320 if (strlcpy(netrc, optarg, sizeof(netrc)) 320 if (strlcpy(netrc, optarg, sizeof(netrc))
321 >= sizeof(netrc)) 321 >= sizeof(netrc))
322 errx(1, "%s: %s", optarg, 322 errx(1, "%s: %s", optarg,
323 strerror(ENAMETOOLONG)); 323 strerror(ENAMETOOLONG));
324 break; 324 break;
325 325
326 case 'o': 326 case 'o':
327 outfile = optarg; 327 outfile = ftp_strdup(optarg);
328 if (strcmp(outfile, "-") == 0) 328 if (strcmp(outfile, "-") == 0)
329 ttyout = stderr; 329 ttyout = stderr;
330 break; 330 break;
331 331
332 case 'p': 332 case 'p':
333 passivemode = 1; 333 passivemode = 1;
334 activefallback = 0; 334 activefallback = 0;
335 break; 335 break;
336 336
337 case 'P': 337 case 'P':
338 ftpport = optarg; 338 ftpport = optarg;
339 break; 339 break;
340 340