Merge pull request #88 from chriskuehl/fix-segfault-on-unknown-args

Fix segfault on invalid arguments
This commit is contained in:
Anthony Sottile 2016-06-17 11:25:48 -07:00 committed by GitHub
commit a6df732935
4 changed files with 15 additions and 2 deletions

View file

@ -1,4 +1,4 @@
FROM debian:jessie
FROM debian:stretch
MAINTAINER Chris Kuehl <ckuehl@yelp.com>

3
debian/control vendored
View file

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

View file

@ -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) {

View file

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