Ejemplo n.º 1
0
    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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 1))
        ret = strlen_approx(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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 3))
        ret = strlen_approx(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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 4))
        ret = strlen_approx(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 4))
Ejemplo n.º 2
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_exact(self.state, s)
     self.assertEqual(ret, 2)
     ret = strlen_approx(self.state, s)
     self.assertEqual(ret, 2)
Ejemplo n.º 3
0
    def test_symbolic_no_fork(self):
        sy = self.state.symbolicate_buffer("+++\0")
        s = self._push_string(sy)

        ret = strlen_approx(self.state, s)
        self.assertItemsEqual(
            range(4),
            Z3Solver.instance().get_all_values(self.state.constraints, ret))

        self.state.constrain(sy[0] == 0)
        ret = strlen_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 0))
        ret = strlen_approx(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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 1))
        ret = strlen_approx(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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 2))
        ret = strlen_approx(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_exact(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 3))
        ret = strlen_approx(self.state, s)
        self.assertTrue(self.state.must_be_true(ret == 3))
Ejemplo n.º 4
0
 def test_concrete_empty(self):
     s = self._push_string("\0")
     ret = strlen_exact(self.state, s)
     self.assertEqual(ret, 0)
     ret = strlen_approx(self.state, s)
     self.assertEqual(ret, 0)
Ejemplo n.º 5
0
 def test_concrete(self):
     s = self._push_string("abc\0")
     ret = strlen_exact(self.state, s)
     self.assertEqual(ret, 3)
     ret = strlen_approx(self.state, s)
     self.assertEqual(ret, 3)