|
6 | 6 | """
|
7 | 7 | import logging
|
8 | 8 | import os
|
| 9 | +import sys |
9 | 10 | import tempfile
|
10 | 11 | import unittest
|
11 | 12 | from test.utils import (
|
@@ -97,6 +98,33 @@ def test_invalid_file_or_directory(self):
|
97 | 98 | main(["cve-bin-tool", "non-existant"])
|
98 | 99 | assert e.value.args[0] == ERROR_CODES[FileNotFoundError]
|
99 | 100 |
|
| 101 | + def test_null_byte_in_filename(self): |
| 102 | + """Test behaviour with an invalid file/directory that contains a \0""" |
| 103 | + |
| 104 | + # Put a null byte into the filename of a real file used in other tests |
| 105 | + CSV_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "csv") |
| 106 | + null_byte_file = os.path.join(CSV_PATH, "test_triage\0.csv") |
| 107 | + |
| 108 | + # for Python 3.8+ this should raise FileNotFound |
| 109 | + if sys.version_info.major == 3 and sys.version_info.minor > 7: |
| 110 | + with pytest.raises(SystemExit) as e: |
| 111 | + main(["cve-bin-tool", null_byte_file]) |
| 112 | + assert e.value.args[0] == ERROR_CODES[FileNotFoundError] |
| 113 | + |
| 114 | + null_byte_file = os.path.join(CSV_PATH, "test_triage.csv\0something") |
| 115 | + with pytest.raises(SystemExit) as e: |
| 116 | + main(["cve-bin-tool", null_byte_file]) |
| 117 | + assert e.value.args[0] == ERROR_CODES[FileNotFoundError] |
| 118 | + |
| 119 | + # for Python 3.7 it will raise a ValueError (embedded null byte) |
| 120 | + if sys.version_info.major == 3 and sys.version_info.minor == 7: |
| 121 | + with pytest.raises(ValueError) as e: |
| 122 | + main(["cve-bin-tool", null_byte_file]) |
| 123 | + |
| 124 | + null_byte_file = os.path.join(CSV_PATH, "test_triage.csv\0something") |
| 125 | + with pytest.raises(ValueError) as e: |
| 126 | + main(["cve-bin-tool", null_byte_file]) |
| 127 | + |
100 | 128 | def test_invalid_parameter(self):
|
101 | 129 | """Test that invalid parmeters exit with expected error code.
|
102 | 130 | ArgParse calls sys.exit(2) for all errors"""
|
|
0 commit comments