Skip to content

Commit

Permalink
Fix segfault on invalid arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuehl committed Jun 17, 2016
1 parent 38dc560 commit b678dbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions dumb-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ char **parse_command(int argc, char *argv[]) {
{"rewrite", required_argument, NULL, 'r'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};
while ((opt = getopt_long(argc, argv, "+hvVcr:", long_options, NULL)) != -1) {
switch (opt) {
Expand Down
8 changes: 8 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def test_no_arguments_prints_usage(both_debug_modes, both_setsid_modes):
)


@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
def test_exits_invalid_with_invalid_args():
proc = Popen(('dumb-init', '--yolo', '/bin/true'), stderr=PIPE)
_, stderr = proc.communicate()
assert proc.returncode == 1
assert stderr == b"dumb-init: unrecognized option '--yolo'\n"


@pytest.mark.parametrize('flag', ['-h', '--help'])
def test_help_message(flag, both_debug_modes, both_setsid_modes, current_version):
"""dumb-init should say something useful when called with the help flag,
Expand Down

0 comments on commit b678dbf

Please sign in to comment.