Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82ff5bc

Browse files
authoredAug 28, 2016
Merge pull request dlang#4753 from jdeschenes/empty_getopt
Fix Issue 16443 - Segmentation fault when option name is empty
2 parents 8343936 + 024b751 commit 82ff5bc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎std/getopt.d

+7
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ private template optionValidator(A...)
649649
args = ["program", "-a"];
650650
getopt(args, config.caseSensitive, 'a', "help string", &opt);
651651
assert(opt);
652+
653+
assertThrown(getopt(args, "", "forgot to put a string", &opt));
652654
}
653655

654656
private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
@@ -671,6 +673,11 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
671673
{
672674
// it's an option string
673675
auto option = to!string(opts[0]);
676+
if (option.length == 0)
677+
{
678+
excep = new GetOptException("An option name may not be an empty string", excep);
679+
return;
680+
}
674681
Option optionHelp = splitAndGet(option);
675682
optionHelp.required = cfg.required;
676683

0 commit comments

Comments
 (0)
Failed to load comments.