Skip to content

Commit a6df732

Browse files
authored
Merge pull request #88 from chriskuehl/fix-segfault-on-unknown-args
Fix segfault on invalid arguments
2 parents 38dc560 + 4ce5ec4 commit a6df732

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:jessie
1+
FROM debian:stretch
22

33
MAINTAINER Chris Kuehl <[email protected]>
44

debian/control

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ Build-Depends:
88
help2man,
99
musl-tools,
1010
## Tests:
11+
procps,
1112
python,
12-
python-pytest,
1313
python-mock,
14+
python-pytest,
1415
Standards-Version: 3.9.7
1516
Homepage: https://github.com/Yelp/dumb-init
1617
Vcs-Browser: https://github.com/Yelp/dumb-init

dumb-init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ char **parse_command(int argc, char *argv[]) {
173173
{"rewrite", required_argument, NULL, 'r'},
174174
{"verbose", no_argument, NULL, 'v'},
175175
{"version", no_argument, NULL, 'V'},
176+
{NULL, 0, NULL, 0},
176177
};
177178
while ((opt = getopt_long(argc, argv, "+hvVcr:", long_options, NULL)) != -1) {
178179
switch (opt) {

tests/cli_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def test_no_arguments_prints_usage(both_debug_modes, both_setsid_modes):
2121
)
2222

2323

24+
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
25+
def test_exits_invalid_with_invalid_args():
26+
proc = Popen(('dumb-init', '--yolo', '/bin/true'), stderr=PIPE)
27+
_, stderr = proc.communicate()
28+
assert proc.returncode == 1
29+
assert stderr in (
30+
b"dumb-init: unrecognized option '--yolo'\n", # glibc
31+
b'dumb-init: unrecognized option: yolo\n', # musl
32+
)
33+
34+
2435
@pytest.mark.parametrize('flag', ['-h', '--help'])
2536
def test_help_message(flag, both_debug_modes, both_setsid_modes, current_version):
2637
"""dumb-init should say something useful when called with the help flag,

0 commit comments

Comments
 (0)