blob: 32839814552afa678a6b8374fe42f85972bcf67d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/env python3
#
# Tests for crashing functions
import os
from unittest import TestCase
import os
import sys
import traceback
import ldb
def segfault_detector(f):
def wrapper(*args, **kwargs):
pid = os.fork()
if pid == 0:
# child, crashing?
try:
f(*args, **kwargs)
except Exception as e:
traceback.print_exc()
sys.stderr.flush()
sys.stdout.flush()
os._exit(0)
# parent, waiting
pid2, status = os.waitpid(pid, 0)
if os.WIFSIGNALED(status):
signal = os.WTERMSIG(status)
raise AssertionError("Failed with signal %d" % signal)
return wrapper
class LdbDnCrashTests(TestCase):
@segfault_detector
def test_ldb_dn_explode_crash(self):
for i in range(106, 150):
dn = ldb.Dn(ldb.Ldb(), "a=b%s,c= " % (' ' * i))
dn.validate()
if __name__ == '__main__':
import unittest
unittest.TestProgram()
|