From b678dbf4b367e6302e0fc31946e072c1e7848a82 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Fri, 17 Jun 2016 10:13:19 -0700 Subject: [PATCH 1/3] Fix segfault on invalid arguments --- dumb-init.c | 1 + tests/cli_test.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/dumb-init.c b/dumb-init.c index af4f92d..f8b3357 100644 --- a/dumb-init.c +++ b/dumb-init.c @@ -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) { diff --git a/tests/cli_test.py b/tests/cli_test.py index 1fe4584..301d512 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -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, From a2df72a6371b06eef4fce7e274065ceacb592a19 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Fri, 17 Jun 2016 11:02:12 -0700 Subject: [PATCH 2/3] Build in stretch instead of jessie to avoid musl bug --- Dockerfile | 2 +- debian/control | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c285385..41f6138 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM debian:stretch MAINTAINER Chris Kuehl diff --git a/debian/control b/debian/control index 5e9c3be..16d054c 100644 --- a/debian/control +++ b/debian/control @@ -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 From 4ce5ec42d2ba5ad6fb0d2afda173f48d0eb38e90 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Fri, 17 Jun 2016 11:06:24 -0700 Subject: [PATCH 3/3] Loosen assertion a bit for musl --- tests/cli_test.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cli_test.py b/tests/cli_test.py index 301d512..2a6065e 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -26,7 +26,10 @@ 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" + 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'])