1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix handling of '--posix' and '--default' (#265)

src/cmd/ksh93/sh/args.c: sh_argopts():
- Remove special-casing for --posix (see also data/builtins.c) and
  move the case -5: to the case ':' instead, so this option is
  handled like all other long options. This change fixes two bugs:
  1. 'set --posix' had no effect on the letoctal or braceexpand
     options. Reproducer:
       $ set --posix
       $ [[ -o braceexpand ]]; echo $?
       0
       $ [[ -o letoctal ]]; echo $?
       1
  2. 'ksh --posix' could not run scripts correctly because it
     wrongly enabled '-c'. Reproducer:
       $ ksh --posix < <(echo 'exit 0')
       ksh: -c requires argument
       Usage: ksh [--posix] [arg ...]
       Help: ksh [ --help | --man ] 2>&1
- Don't allow 'set --default' to unset the restricted option.

src/cmd/ksh93/tests/options.sh:
- Add regression tests for the bugs described above, using -o posix
  and --posix.

src/cmd/ksh93/tests/restricted.sh:
- Add a regression test for 'set --default' in rksh.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-04-09 15:26:07 -07:00 committed by GitHub
parent cb67a01b45
commit 5461f11968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 12 deletions

View file

@ -176,18 +176,12 @@ int sh_argopts(int argc,register char *argv[], void *context)
UNREACHABLE();
}
break;
case -5: /* --posix must be handled explicitly to stop AST optget(3) overriding it */
if(opt_info.num)
on_option(&newflags,SH_POSIX);
else
off_option(&newflags,SH_POSIX);
break;
case -6: /* --default */
{
register const Shtable_t *tp;
for(tp=shtab_options; o = tp->sh_number; tp++)
if(!(o&SH_COMMANDLINE) && is_option(&newflags,o&0xff))
off_option(&newflags,o&0xff);
if(!(o&SH_COMMANDLINE) && (o&=0xff)!=SH_RESTRICTED && is_option(&newflags,o))
off_option(&newflags,o);
}
defaultflag++;
continue;
@ -231,6 +225,7 @@ int sh_argopts(int argc,register char *argv[], void *context)
if(cp=strchr(optksh,n))
o = flagval[cp-optksh];
break;
case -5: /* --posix must be handled explicitly to stop AST optget(3) overriding it */
case ':':
if(opt_info.name[0]=='-'&&opt_info.name[1]=='-')
{