Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault on invalid arguments #88

Merged
merged 3 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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