summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2013-08-09 03:37:26 +0000
committerDamien Miller <djm@cvs.openbsd.org>2013-08-09 03:37:26 +0000
commitf91c105009048049e7cc0830c2c06c44839d51de (patch)
treef19038f3abd3a3af4f618b4d24ed3255e32736ad /usr.bin/ssh
parent4abe90733a77a3d273d8fafa9e0901a0e42934ca (diff)
do getopt parsing for all sftp commands (with an empty optstring for
commands without arguments) to ensure consistent behaviour
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/sftp.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c
index ffb3a682b87..7445f695860 100644
--- a/usr.bin/ssh/sftp.c
+++ b/usr.bin/ssh/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.152 2013/08/08 05:04:03 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.153 2013/08/09 03:37:25 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -498,6 +498,26 @@ parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag)
}
static int
+parse_no_flags(const char *cmd, char **argv, int argc)
+{
+ extern int opterr, optind, optopt, optreset;
+ int ch;
+
+ optind = optreset = 1;
+ opterr = 0;
+
+ while ((ch = getopt(argc, argv, "")) != -1) {
+ switch (ch) {
+ default:
+ error("%s: Invalid flag -%c", cmd, optopt);
+ return -1;
+ }
+ }
+
+ return optind;
+}
+
+static int
is_dir(char *path)
{
struct stat sb;
@@ -1219,6 +1239,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
return -1;
goto parse_two_paths;
case I_SYMLINK:
+ if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
+ return -1;
parse_two_paths:
if (argc - optidx < 2) {
error("You must specify two paths after a %s "
@@ -1237,6 +1259,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
case I_CHDIR:
case I_LCHDIR:
case I_LMKDIR:
+ if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
+ return -1;
/* Get pathname (mandatory) */
if (argc - optidx < 1) {
error("You must specify a path after a %s command.",
@@ -1278,6 +1302,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
base = 8;
case I_CHOWN:
case I_CHGRP:
+ if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
+ return -1;
/* Get numeric arg (mandatory) */
if (argc - optidx < 1)
goto need_num_arg;
@@ -1308,6 +1334,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
case I_HELP:
case I_VERSION:
case I_PROGRESS:
+ if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
+ return -1;
break;
default:
fatal("Command not implemented");