summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-08-21 02:41:46 +1000
committerDamien Miller <djm@mindrot.org>2013-08-21 02:41:46 +1000
commit036d30743fc914089f9849ca52d615891d47e616 (patch)
treec2dada7bd0a723e96e697ed30f8dd450a3998577
parentc7dba12bf95eb1d69711881a153cc286c1987663 (diff)
- djm@cvs.openbsd.org 2013/08/09 03:37:25
[sftp.c] do getopt parsing for all sftp commands (with an empty optstring for commands without arguments) to ensure consistent behaviour
-rw-r--r--ChangeLog5
-rw-r--r--sftp.c30
2 files changed, 34 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index cd46b83aa..f78dce6ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,11 @@
26 posix-rename@openssh.com extension. 26 posix-rename@openssh.com extension.
27 27
28 intended for use in regress tests, so no documentation. 28 intended for use in regress tests, so no documentation.
29 - djm@cvs.openbsd.org 2013/08/09 03:37:25
30 [sftp.c]
31 do getopt parsing for all sftp commands (with an empty optstring for
32 commands without arguments) to ensure consistent behaviour
33
2920130808 3420130808
30 - (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt 35 - (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt
31 since some platforms (eg really old FreeBSD) don't have it. Instead, 36 since some platforms (eg really old FreeBSD) don't have it. Instead,
diff --git a/sftp.c b/sftp.c
index 66ab2b0d4..1ddfef6b5 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.152 2013/08/08 05:04:03 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.153 2013/08/09 03:37:25 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -519,6 +519,26 @@ parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag)
519} 519}
520 520
521static int 521static int
522parse_no_flags(const char *cmd, char **argv, int argc)
523{
524 extern int opterr, optind, optopt, optreset;
525 int ch;
526
527 optind = optreset = 1;
528 opterr = 0;
529
530 while ((ch = getopt(argc, argv, "")) != -1) {
531 switch (ch) {
532 default:
533 error("%s: Invalid flag -%c", cmd, optopt);
534 return -1;
535 }
536 }
537
538 return optind;
539}
540
541static int
522is_dir(char *path) 542is_dir(char *path)
523{ 543{
524 struct stat sb; 544 struct stat sb;
@@ -1240,6 +1260,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
1240 return -1; 1260 return -1;
1241 goto parse_two_paths; 1261 goto parse_two_paths;
1242 case I_SYMLINK: 1262 case I_SYMLINK:
1263 if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1264 return -1;
1243 parse_two_paths: 1265 parse_two_paths:
1244 if (argc - optidx < 2) { 1266 if (argc - optidx < 2) {
1245 error("You must specify two paths after a %s " 1267 error("You must specify two paths after a %s "
@@ -1258,6 +1280,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
1258 case I_CHDIR: 1280 case I_CHDIR:
1259 case I_LCHDIR: 1281 case I_LCHDIR:
1260 case I_LMKDIR: 1282 case I_LMKDIR:
1283 if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1284 return -1;
1261 /* Get pathname (mandatory) */ 1285 /* Get pathname (mandatory) */
1262 if (argc - optidx < 1) { 1286 if (argc - optidx < 1) {
1263 error("You must specify a path after a %s command.", 1287 error("You must specify a path after a %s command.",
@@ -1299,6 +1323,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
1299 base = 8; 1323 base = 8;
1300 case I_CHOWN: 1324 case I_CHOWN:
1301 case I_CHGRP: 1325 case I_CHGRP:
1326 if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1327 return -1;
1302 /* Get numeric arg (mandatory) */ 1328 /* Get numeric arg (mandatory) */
1303 if (argc - optidx < 1) 1329 if (argc - optidx < 1)
1304 goto need_num_arg; 1330 goto need_num_arg;
@@ -1329,6 +1355,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
1329 case I_HELP: 1355 case I_HELP:
1330 case I_VERSION: 1356 case I_VERSION:
1331 case I_PROGRESS: 1357 case I_PROGRESS:
1358 if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1359 return -1;
1332 break; 1360 break;
1333 default: 1361 default:
1334 fatal("Command not implemented"); 1362 fatal("Command not implemented");