summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2021-11-17 10:23:02 +1300
committerRalph Boehme <slow@samba.org>2021-11-17 04:36:36 +0000
commitc3194d0d65d838b79cb5345a9d9433704b2f95ba (patch)
treec7604c5ff67ed48d7bc81590377700749747858f
parentfccb105e079df7bfe22b6887262128ab9e81064d (diff)
downloadsamba-c3194d0d65d838b79cb5345a9d9433704b2f95ba.tar.gz
test/bad_chars: ensure our tests could fail
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r--python/samba/tests/source_chars.py13
-rw-r--r--testdata/source-chars-bad.c23
2 files changed, 36 insertions, 0 deletions
diff --git a/python/samba/tests/source_chars.py b/python/samba/tests/source_chars.py
index 5d107e09574..bfaf6f34ee1 100644
--- a/python/samba/tests/source_chars.py
+++ b/python/samba/tests/source_chars.py
@@ -63,6 +63,7 @@ IGNORED_FILES = {
'source3/selftest/ktest-krb5_ccache-2',
'source3/selftest/ktest-krb5_ccache-3',
'third_party/pep8/testsuite/latin-1.py',
+ 'testdata/source-chars-bad.c',
}
IGNORED_EXTENSIONS = {
@@ -205,6 +206,18 @@ class CharacterTests(TestCase):
if is_bad_char(c):
self.fail(f"{name} has potentially bad format characters!")
+ def test_unexpected_format_chars_do_fail(self):
+ """Test the test"""
+ for name, n_bad in [
+ ('testdata/source-chars-bad.c', 3)
+ ]:
+ fullname = os.path.join(ROOT, name)
+ with open(fullname) as f:
+ s = f.read()
+ chars = set(s)
+ bad_chars = [c for c in chars if is_bad_char(c)]
+ self.assertEqual(len(bad_chars), n_bad)
+
def check_file_text():
"""If called directly as a script, count the found characters."""
diff --git a/testdata/source-chars-bad.c b/testdata/source-chars-bad.c
new file mode 100644
index 00000000000..9b435722e13
--- /dev/null
+++ b/testdata/source-chars-bad.c
@@ -0,0 +1,23 @@
+/*
+ * "Trojan Source" CVE-2021-42574 test.
+ *
+ * Based on an example from https://lwn.net/Articles/874951/
+ */
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ int isAdmin = 0;
+
+#if 0
+ /* This is what is really there. */
+
+ /*«RLO» } «LRI»if (isAdmin)«PDI» «LRI» begin admins only */
+ puts("hello admin");
+ /* end admin only «RLO» { «LRI»*/
+#else
+ /*‮ } ⁦if (isAdmin)⁩ ⁦ begin admins only */
+ puts("hello admin");
+ /* end admin only ‮ { ⁦*/
+#endif
+}