From 58bbcdb1837c2f98cd3e1dd04f47ef369b026a18 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 14 Aug 2015 21:44:15 +0000 Subject: [PATCH] sh: When setting option via long name, don't go via letter. Looking up the letter makes no sense and prevents adding options that only have a long name, no letter. --- bin/sh/options.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/sh/options.c b/bin/sh/options.c index 2d0ddce5a3de..1568937a53ed 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -73,6 +73,7 @@ char *minusc; /* argument to -c option */ static void options(int); static void minus_o(char *, int); static void setoption(int, int); +static void setoptionbyindex(int, int); static int getopts(char *, char *, char **, char ***, char **); @@ -269,7 +270,7 @@ minus_o(char *name, int val) } else { for (i = 0; i < NOPTS; i++) if (equal(name, optlist[i].name)) { - setoption(optlist[i].letter, val); + setoptionbyindex(i, val); return; } error("Illegal option -o %s", name); @@ -278,26 +279,32 @@ minus_o(char *name, int val) static void -setoption(int flag, int val) +setoptionbyindex(int idx, int val) { - int i; - - if (flag == 'p' && !val && privileged) { + if (optlist[idx].letter == 'p' && !val && privileged) { if (setgid(getgid()) == -1) error("setgid"); if (setuid(getuid()) == -1) error("setuid"); } + optlist[idx].val = val; + if (val) { + /* #%$ hack for ksh semantics */ + if (optlist[idx].letter == 'V') + Eflag = 0; + else if (optlist[idx].letter == 'E') + Vflag = 0; + } +} + +static void +setoption(int flag, int val) +{ + int i; + for (i = 0; i < NOPTS; i++) if (optlist[i].letter == flag) { - optlist[i].val = val; - if (val) { - /* #%$ hack for ksh semantics */ - if (flag == 'V') - Eflag = 0; - else if (flag == 'E') - Vflag = 0; - } + setoptionbyindex(i, val); return; } error("Illegal option -%c", flag);