def test_symbolic(self): sy = self.state.symbolicate_buffer("+++\0") s = self._push_string(sy) ret = strlen(self.state, s) self.assertItemsEqual( range(4), Z3Solver.instance().get_all_values(self.state.constraints, ret)) self.state.constrain(sy[0] == 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 0)) self._clear_constraints() self.state.constrain(sy[0] != 0) self.state.constrain(sy[1] == 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 1)) self._clear_constraints() self.state.constrain(sy[0] != 0) self.state.constrain(sy[1] != 0) self.state.constrain(sy[2] == 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 2)) self._clear_constraints() self.state.constrain(sy[0] != 0) self.state.constrain(sy[1] != 0) self.state.constrain(sy[2] != 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 3))
def test_symbolic_mixed(self): sy = self.state.symbolicate_buffer("a+b+\0") s = self._push_string(sy) self.state.constrain(sy[1] == 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 1)) self._clear_constraints() self.state.constrain(sy[1] != 0) self.state.constrain(sy[3] == 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 3)) self._clear_constraints() self.state.constrain(sy[1] != 0) self.state.constrain(sy[3] != 0) ret = strlen(self.state, s) self.assertTrue(self.state.must_be_true(ret == 4))
def test_concrete_empty(self): s = self._push_string("\0") ret = strlen(self.state, s) self.assertEqual(ret, 0)
def test_symbolic_effective_null(self): sy = self.state.symbolicate_buffer("ab+") self.state.constrain(sy[2] == 0) s = self._push_string(sy) ret = strlen(self.state, s) self.assertEqual(ret, 2)
def test_concrete(self): s = self._push_string("abc\0") ret = strlen(self.state, s) self.assertEqual(ret, 3)