summaryrefslogtreecommitdiffstats
path: root/bin/ps/ps.c
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2002-06-20 14:55:53 +0000
committersobomax <sobomax@FreeBSD.org>2002-06-20 14:55:53 +0000
commit8e683e45efc4dc54cc0c85c2d7de550694a4abc9 (patch)
treeddf5635a9feec3b37cefc9360e53c9cb30fa1cf9 /bin/ps/ps.c
parentddd0934a7cf74148bd18ae54dfa8ce6c3b92be2a (diff)
downloadFreeBSD-src-8e683e45efc4dc54cc0c85c2d7de550694a4abc9.zip
FreeBSD-src-8e683e45efc4dc54cc0c85c2d7de550694a4abc9.tar.gz
Don't try to decode old-style options if the argv[1] begins with `-' and the
second character represents some option taking an argument. This fixes problem when ps(1) is invoked for examply as follows: $ ps -Ufoobar1234 the above example results in option string being interpreted as -U foobarp1234 - note extra `p'. Reported by: Vladimir Sotnikov <vovan@kyivstar.net> MFC after: 2 weeks
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r--bin/ps/ps.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index f808cd5..515e9f3 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -114,6 +114,12 @@ static char Zfmt[] = "lvl";
static kvm_t *kd;
+#if defined(LAZY_PS)
+#define PS_ARGS "aCcefghjLlM:mN:O:o:p:rSTt:U:uvwxZ"
+#else
+#define PS_ARGS "aCceghjLlM:mN:O:o:p:rSTt:U:uvwxZ"
+#endif
+
int
main(int argc, char *argv[])
{
@@ -123,11 +129,11 @@ main(int argc, char *argv[])
dev_t ttydev;
pid_t pid;
uid_t *uids;
- int all, ch, flag, i, _fmt, lineno, nentries, dropgid;
+ int all, ch, flag, i, _fmt, lineno, nentries, nocludge, dropgid;
int prtheader, wflag, what, xflg, uid, nuids;
char *cols;
char errbuf[_POSIX2_LINE_MAX];
- const char *nlistf, *memf;
+ const char *cp, *nlistf, *memf;
(void) setlocale(LC_ALL, "");
/* Set the time to what it is right now. */
@@ -143,8 +149,25 @@ main(int argc, char *argv[])
else
termwidth = ws.ws_col - 1;
- if (argc > 1)
- argv[1] = kludge_oldps_options(argv[1]);
+ /*
+ * Don't apply a kludge if the first argument is an option taking an
+ * argument
+ */
+ if (argc > 1) {
+ nocludge = 0;
+ if (argv[1][0] == '-') {
+ for (cp = PS_ARGS; *cp != '\0'; cp++) {
+ if (*cp != ':')
+ continue;
+ if (*(cp - 1) == argv[1][1]) {
+ nocludge = 1;
+ break;
+ }
+ }
+ }
+ if (nocludge == 0)
+ argv[1] = kludge_oldps_options(argv[1]);
+ }
all = _fmt = prtheader = wflag = xflg = 0;
pid = -1;
@@ -153,12 +176,7 @@ main(int argc, char *argv[])
ttydev = NODEV;
dropgid = 0;
memf = nlistf = _PATH_DEVNULL;
- while ((ch = getopt(argc, argv,
-#if defined(LAZY_PS)
- "aCcefghjLlM:mN:O:o:p:rSTt:U:uvwxZ")) != -1)
-#else
- "aCceghjLlM:mN:O:o:p:rSTt:U:uvwxZ")) != -1)
-#endif
+ while ((ch = getopt(argc, argv, PS_ARGS)) != -1)
switch((char)ch) {
case 'a':
all = 1;
OpenPOWER on IntegriCloud