-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optget(3): Fix crash on unexpected long option value (re: 9fcd023)
@dnewhall reports: > Found this while testing a very long optstring that had a typo. > > For the following snippet of code in opttest.ksh: > > optstring="f(file)" > while getopts "$optstring" opt > do > print -- "$opt: $OPTARG" > done > > If you accidentally add a parameter using =, you get a > segmentation fault: > > $ opttest.ksh --file=foo > Segmentation fault (core dumped) > > Obviously, calling with --file foo doesn't break it. > > (The correct optstring was supposed to be "f:(file)", which works.) The bug is worse; the crash is also triggered for a correct options string, when an option-argument is given for a long option that doesn't expect one. For example, set --default=foo, ksh --posix=foo, /opt/ast/bin/cp --preserve=foo all crash. Analysis: In the referenced commit I incorrectly assumed that nothing ever calles optnumber() with a third argument of NULL (int *e, a pointer through which to pass back the value of errno before restoring it), so that commit removed the check for e==NULL from optget.c:4145. However, in optget.c:5242, there is an optnumber() call I overlooked that does pass a third argument of NULL. src/lib/libast/misc/optget.c: optnum(): - Restore the check for non-NULL e before dereferencing e. Resolves: #794
- Loading branch information
Showing
5 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters