diff options
author | Taylor Yu <catalyst@torproject.org> | 2019-04-10 12:27:50 -0500 |
---|---|---|
committer | Taylor Yu <catalyst@torproject.org> | 2019-04-30 13:18:46 -0500 |
commit | 58ec88e8060508a253bbe8ba5c19b020a2629ea0 (patch) | |
tree | 9ad91a15d49d4a8a53d8142e92e3412f8ef5f1ee /scripts/coccinelle/ctrl-reply-cleanup.cocci | |
parent | 769eb07a7a3bd93091ca1677564d3de62e3c5c2c (diff) | |
download | tor-58ec88e8060508a253bbe8ba5c19b020a2629ea0.tar.gz tor-58ec88e8060508a253bbe8ba5c19b020a2629ea0.zip |
Coccinelle scripts for control.c refactor
Diffstat (limited to 'scripts/coccinelle/ctrl-reply-cleanup.cocci')
-rw-r--r-- | scripts/coccinelle/ctrl-reply-cleanup.cocci | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/coccinelle/ctrl-reply-cleanup.cocci b/scripts/coccinelle/ctrl-reply-cleanup.cocci new file mode 100644 index 0000000000..f085cd4684 --- /dev/null +++ b/scripts/coccinelle/ctrl-reply-cleanup.cocci @@ -0,0 +1,43 @@ +// Script to clean up after ctrl-reply.cocci -- run as a separate step +// because cleanup_write2 (even when disabled) somehow prevents the +// match rule in ctrl-reply.cocci from matching. + +// If it doesn't have to be a printf, turn it into a write + +@ cleanup_write @ +expression E; +constant code, s; +@@ +-control_printf_endreply(E, code, s) ++control_write_endreply(E, code, s) + +// Use send_control_done() instead of explicitly writing it out +@ cleanup_send_done @ +type T; +identifier f != send_control_done; +expression E; +@@ + T f(...) { +<... +-control_write_endreply(E, 250, "OK") ++send_control_done(E) + ...> + } + +// Clean up more printfs that could be writes +// +// For some reason, including this rule, even disabled, causes the +// match rule in ctrl-reply.cocci to fail to match some code that has +// %s in its format strings + +@ cleanup_write2 @ +expression E1, E2; +constant code; +@@ +( +-control_printf_endreply(E1, code, "%s", E2) ++control_write_endreply(E1, code, E2) +| +-control_printf_midreply(E1, code, "%s", E2) ++control_write_midreply(E1, code, E2) +) |