Skip to content

Commit

Permalink
AugAssign propagates taint
Browse files Browse the repository at this point in the history
Before, the variable would be tainted only if the last += was tainted.

Now

url = 'http://'
url += TAINT
url += '?x=y'

url marked as tainted.
  • Loading branch information
Ben Caller committed Jul 27, 2018
1 parent 8c24cc8 commit 0cfc1b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyt/cfg/stmt_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,12 @@ def visit_AugAssign(self, node):
rhs_visitor = RHSVisitor()
rhs_visitor.visit(node.value)

lhs = extract_left_hand_side(node.target)
return self.append_node(AssignmentNode(
label.result,
extract_left_hand_side(node.target),
lhs,
node,
rhs_visitor.result,
rhs_visitor.result + [lhs],
path=self.filenames[-1]
))

Expand Down
8 changes: 8 additions & 0 deletions tests/cfg/cfg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,14 @@ def test_assignment_starred_list(self):
[('a', ['d']), ('b', ['d']), ('c', ['e'])],
)

def test_augmented_assignment(self):
self.cfg_create_from_ast(ast.parse('a+=f(b,c)'))

(node,) = self.cfg.nodes[1:-1]
self.assertEqual(node.label, 'a += f(b, c)')
self.assertEqual(node.left_hand_side, 'a')
self.assertEqual(node.right_hand_side_variables, ['b', 'c', 'a'])


class CFGComprehensionTest(CFGBaseTestCase):
def test_nodes(self):
Expand Down

0 comments on commit 0cfc1b0

Please sign in to comment.