Skip to content

Commit

Permalink
Merge pull request #88 from chriskuehl/fix-segfault-on-unknown-args
Browse files Browse the repository at this point in the history
Fix segfault on invalid arguments
  • Loading branch information
asottile committed Jun 17, 2016
2 parents 38dc560 + 4ce5ec4 commit a6df732
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:jessie
FROM debian:stretch

MAINTAINER Chris Kuehl <ckuehl@yelp.com>

Expand Down
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Build-Depends:
help2man,
musl-tools,
## Tests:
procps,
python,
python-pytest,
python-mock,
python-pytest,
Standards-Version: 3.9.7
Homepage: https://github.com/Yelp/dumb-init
Vcs-Browser: https://github.com/Yelp/dumb-init
Expand Down
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
11 changes: 11 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ 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 in (
b"dumb-init: unrecognized option '--yolo'\n", # glibc
b'dumb-init: unrecognized option: yolo\n', # musl
)


@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 a6df732

Please sign in to comment.