summaryrefslogtreecommitdiffstats
path: root/cocci
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 07:24:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 07:24:22 +0000
commit45d6379135504814ab723b57f0eb8be23393a51d (patch)
treed4f2ec4acca824a8446387a758b0ce4238a4dffa /cocci
parentInitial commit. (diff)
downloadbind9-45d6379135504814ab723b57f0eb8be23393a51d.tar.xz
bind9-45d6379135504814ab723b57f0eb8be23393a51d.zip
Adding upstream version 1:9.16.44.upstream/1%9.16.44upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cocci')
-rw-r--r--cocci/UV_RUNTIME_CHECK.spatch8
-rw-r--r--cocci/config-h.spatch4
-rw-r--r--cocci/dns_message_create.spatch84
-rw-r--r--cocci/dns_message_destroy.spatch6
-rw-r--r--cocci/dns_name_copy-with-result.spatch30
-rw-r--r--cocci/dns_name_copy.spatch30
-rw-r--r--cocci/dns_name_copynf.spatch6
-rw-r--r--cocci/dns_name_dup.disabled40
-rw-r--r--cocci/dns_rbtnodechain_init.disabled7
-rw-r--r--cocci/isc_buffer_allocate_never_fail.spatch84
-rw-r--r--cocci/isc_event_allocat_never_fail.spatch33
-rw-r--r--cocci/isc_mem_allocate_never_fail.spatch41
-rw-r--r--cocci/isc_mem_create_never_fail.disabled95
-rw-r--r--cocci/isc_mem_get_never_fail.spatch41
-rw-r--r--cocci/isc_mem_putanddetach.spatch8
-rw-r--r--cocci/isc_mem_strdup_never_fail.spatch33
-rw-r--r--cocci/isc_mempool_create_cannot_fail.cocci49
-rw-r--r--cocci/memcpy.spatch14
-rw-r--r--cocci/null-the-pointer-early.disabled21
-rw-r--r--cocci/return-void-from-void.spatch19
-rw-r--r--cocci/unreachable.spatch19
21 files changed, 672 insertions, 0 deletions
diff --git a/cocci/UV_RUNTIME_CHECK.spatch b/cocci/UV_RUNTIME_CHECK.spatch
new file mode 100644
index 0000000..6a50195
--- /dev/null
+++ b/cocci/UV_RUNTIME_CHECK.spatch
@@ -0,0 +1,8 @@
+@@
+expression E;
+int R;
+@@
+
+ R = E(...);
+- UV_RUNTIME_CHECK(...);
++ UV_RUNTIME_CHECK(E, R);
diff --git a/cocci/config-h.spatch b/cocci/config-h.spatch
new file mode 100644
index 0000000..82ef3e8
--- /dev/null
+++ b/cocci/config-h.spatch
@@ -0,0 +1,4 @@
+@@
+@@
+
+- #include <config.h>
diff --git a/cocci/dns_message_create.spatch b/cocci/dns_message_create.spatch
new file mode 100644
index 0000000..bab6d58
--- /dev/null
+++ b/cocci/dns_message_create.spatch
@@ -0,0 +1,84 @@
+@@
+statement S;
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- if (V != ISC_R_SUCCESS) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- if (V == ISC_R_SUCCESS)
+ S1
+- else S2
+
+@@
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- check_result(V, ...);
+
+@@
+@@
+
+- CHECK(
+ dns_message_create(...)
+- )
+ ;
+
+@@
+@@
+
+- DO(...,
+ dns_message_create(...)
+- )
+ ;
+
+@@
+@@
+
+- RETERR(
+ dns_message_create(...)
+- )
+ ;
+
+@@
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- assert_int_equal(V, ISC_R_SUCCESS);
+
+@@
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- CHECK(..., V);
+
+@@
+expression V;
+statement S;
+@@
+
+- V =
+ dns_message_create(...);
+- if (ISC_UNLIKELY(V != ISC_R_SUCCESS)) S
+
+@@
+expression V;
+@@
+
+- V =
+ dns_message_create(...);
+- RUNTIME_CHECK(V == ISC_R_SUCCESS);
diff --git a/cocci/dns_message_destroy.spatch b/cocci/dns_message_destroy.spatch
new file mode 100644
index 0000000..4043525
--- /dev/null
+++ b/cocci/dns_message_destroy.spatch
@@ -0,0 +1,6 @@
+@@
+expression M;
+@@
+
+- dns_message_destroy(M);
++ dns_message_detach(M);
diff --git a/cocci/dns_name_copy-with-result.spatch b/cocci/dns_name_copy-with-result.spatch
new file mode 100644
index 0000000..c4555c3
--- /dev/null
+++ b/cocci/dns_name_copy-with-result.spatch
@@ -0,0 +1,30 @@
+@@
+expression V, E1, E2;
+statement S;
+@@
+
+- V = dns_name_copy(E1, E2, NULL);
+- if (V != ISC_R_SUCCESS) S
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
+
+@@
+expression V, E1, E2;
+statement S1, S2;
+@@
+
+- V = dns_name_copy(E1, E2, NULL);
+- if (V == ISC_R_SUCCESS) S1 else S2;
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
++ S2
+
+@@
+expression V, E1, E2;
+statement S1, S2;
+@@
+
+- V = dns_name_copy(E1, E2, NULL);
+- S1
+- if (V == ISC_R_SUCCESS) S2
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
++ S1
++ S2
diff --git a/cocci/dns_name_copy.spatch b/cocci/dns_name_copy.spatch
new file mode 100644
index 0000000..89e340c
--- /dev/null
+++ b/cocci/dns_name_copy.spatch
@@ -0,0 +1,30 @@
+@@
+expression E1, E2;
+@@
+
+- dns_name_copy(E1, E2, NULL);
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
+
+@@
+expression E1, E2;
+@@
+
+- (void)dns_name_copy(E1, E2, NULL);
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
+
+@@
+expression E1, E2;
+@@
+
+- return (dns_name_copy(E1, E2, NULL));
++ RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
++ return (ISC_R_SUCCESS);
+
+// ./bin/named/query.c processing broken with this rule, fix manually
+// @@
+// expression V, E1, E2;
+// @@
+//
+// - V = dns_name_copy(E1, E2, NULL);
+// - RUNTIME_CHECK(V == ISC_R_SUCCESS);
+// + RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
diff --git a/cocci/dns_name_copynf.spatch b/cocci/dns_name_copynf.spatch
new file mode 100644
index 0000000..7853b67
--- /dev/null
+++ b/cocci/dns_name_copynf.spatch
@@ -0,0 +1,6 @@
+@@
+expression E1, E2;
+@@
+
+- RUNTIME_CHECK(dns_name_copy(E1, E2, NULL) == ISC_R_SUCCESS);
++ dns_name_copynf(E1, E2);
diff --git a/cocci/dns_name_dup.disabled b/cocci/dns_name_dup.disabled
new file mode 100644
index 0000000..42eddce
--- /dev/null
+++ b/cocci/dns_name_dup.disabled
@@ -0,0 +1,40 @@
+@@
+expression E1, E2, E3;
+statement S;
+expression V;
+@@
+
+- V = dns_name_dup(E1, E2, E3);
++ dns_name_dup(E1, E2, E3);
+- if (V != ISC_R_SUCCESS) S
+
+@@
+expression E1, E2, E3;
+statement S1, S2;
+expression V;
+@@
+
+- V = dns_name_dup(E1, E2, E3);
+- if (V != ISC_R_SUCCESS) S1 else { S2 }
++ dns_name_dup(E1, E2, E3);
++ S2
+
+@@
+expression E1, E2, E3;
+expression V;
+@@
+
+- V = dns_name_dup(E1, E2, E3);
+- RUNTIME_CHECK(V == ISC_R_SUCCESS);
++ dns_name_dup(E1, E2, E3);
+
+@@
+expression E1, E2, E3;
+statement S1, S2;
+expression V;
+@@
+
+- V = dns_name_dup(E1, E2, E3);
++ dns_name_dup(E1, E2, E3);
+S1
+- if (V != ISC_R_SUCCESS) S2
diff --git a/cocci/dns_rbtnodechain_init.disabled b/cocci/dns_rbtnodechain_init.disabled
new file mode 100644
index 0000000..1c02a83
--- /dev/null
+++ b/cocci/dns_rbtnodechain_init.disabled
@@ -0,0 +1,7 @@
+@@
+expression C;
+expression M;
+@@
+
+- dns_rbtnodechain_init(C, M);
++ dns_rbtnodechain_init(C);
diff --git a/cocci/isc_buffer_allocate_never_fail.spatch b/cocci/isc_buffer_allocate_never_fail.spatch
new file mode 100644
index 0000000..b632e4e
--- /dev/null
+++ b/cocci/isc_buffer_allocate_never_fail.spatch
@@ -0,0 +1,84 @@
+@@
+statement S;
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- if (V != ISC_R_SUCCESS) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- if (V == ISC_R_SUCCESS)
+ S1
+- else S2
+
+@@
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- check_result(V, ...);
+
+@@
+@@
+
+- CHECK(
+ isc_buffer_allocate(...)
+- )
+ ;
+
+@@
+@@
+
+- DO(...,
+ isc_buffer_allocate(...)
+- )
+ ;
+
+@@
+@@
+
+- RETERR(
+ isc_buffer_allocate(...)
+- )
+ ;
+
+@@
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- assert_int_equal(V, ISC_R_SUCCESS);
+
+@@
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- CHECK(..., V);
+
+@@
+expression V;
+statement S;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- if (ISC_UNLIKELY(V != ISC_R_SUCCESS)) S
+
+@@
+expression V;
+@@
+
+- V =
+ isc_buffer_allocate(...);
+- RUNTIME_CHECK(V == ISC_R_SUCCESS);
diff --git a/cocci/isc_event_allocat_never_fail.spatch b/cocci/isc_event_allocat_never_fail.spatch
new file mode 100644
index 0000000..eab2265
--- /dev/null
+++ b/cocci/isc_event_allocat_never_fail.spatch
@@ -0,0 +1,33 @@
+@@
+statement S;
+expression V;
+@@
+
+V = isc_event_allocate(...);
+- if (V == NULL) S
+
+@@
+type T;
+statement S;
+expression V;
+@@
+
+V = (T *)isc_event_allocate(...);
+- if (V == NULL) S
+
+@@
+statement S;
+expression V;
+@@
+
+if (V == NULL) V = isc_event_allocate(...);
+- if (V == NULL) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+V = isc_event_allocate(...);
+- if (V == NULL) S1 else { S2 }
++ S2
diff --git a/cocci/isc_mem_allocate_never_fail.spatch b/cocci/isc_mem_allocate_never_fail.spatch
new file mode 100644
index 0000000..c7e6069
--- /dev/null
+++ b/cocci/isc_mem_allocate_never_fail.spatch
@@ -0,0 +1,41 @@
+@@
+statement S;
+expression V;
+@@
+
+V = isc_mem_allocate(...);
+- if (V == NULL) S
+
+@@
+type T;
+statement S;
+expression V;
+@@
+
+V = (T *)isc_mem_allocate(...);
+- if (V == NULL) S
+
+@@
+statement S;
+expression V;
+@@
+
+if (V == NULL) V = isc_mem_allocate(...);
+- if (V == NULL) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+V = isc_mem_allocate(...);
+- if (V == NULL) S1 else { S2 }
++ S2
+
+@@
+type T;
+expression V, E1, E2;
+@@
+
+- V = (T)isc_mem_allocate(E1, E2);
++ V = isc_mem_allocate(E1, E2);
diff --git a/cocci/isc_mem_create_never_fail.disabled b/cocci/isc_mem_create_never_fail.disabled
new file mode 100644
index 0000000..e526506
--- /dev/null
+++ b/cocci/isc_mem_create_never_fail.disabled
@@ -0,0 +1,95 @@
+@@
+statement S;
+expression E;
+@@
+
+- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S;
++ isc_mem_create(E);
+
+@@
+statement S;
+expression V, E;
+@@
+
+- V = isc_mem_create(0, 0, E);
+- if (V == ISC_R_SUCCESS) S
++ isc_mem_create(E);
++ S
+
+
+@@
+statement S;
+expression V, E;
+@@
+
+- V = isc_mem_create(0, 0, E);
+- if (V != ISC_R_SUCCESS) S
++ isc_mem_create(E);
+
+@@
+expression V, E;
+@@
+
+- V = isc_mem_create(0, 0, E);
+- check_result(V, ...);
++ isc_mem_create(E);
+
+@@
+statement S;
+expression V, E, C;
+@@
+
+- if (C) { V = isc_mem_create(0, 0, E); }
+- if (V != ISC_R_SUCCESS) S
++ if (C) { isc_mem_create(E); }
+
+@@
+expression E;
+@@
+
+- RUNTIME_CHECK(isc_mem_create(0, 0, E) == ISC_R_SUCCESS);
++ isc_mem_create(E);
+
+@@
+expression E;
+@@
+
+- RUNCHECK(isc_mem_create(0, 0, E));
++ isc_mem_create(E);
+
+@@
+expression E;
+@@
+
+- CHECK(isc_mem_create(0, 0, E), ...);
++ isc_mem_create(E);
+
+@@
+expression E;
+@@
+
+- CHECK(isc_mem_create(0, 0, E));
++ isc_mem_create(E);
+
+@@
+expression V, E;
+@@
+
+- V = isc_mem_create(0, 0, E);
+- assert_int_equal(V, ISC_R_SUCCESS);
++ isc_mem_create(E);
+
+@@
+expression E;
+statement S;
+@@
+
+- if (isc_mem_create(0, 0, E) != ISC_R_SUCCESS) S
++ isc_mem_create(E);
+
+@@
+expression E;
+@@
+
+- DO(..., isc_mem_create(0, 0, E));
++ isc_mem_create(E);
diff --git a/cocci/isc_mem_get_never_fail.spatch b/cocci/isc_mem_get_never_fail.spatch
new file mode 100644
index 0000000..e79a040
--- /dev/null
+++ b/cocci/isc_mem_get_never_fail.spatch
@@ -0,0 +1,41 @@
+@@
+statement S;
+expression V;
+@@
+
+V = isc_mem_get(...);
+- if (V == NULL) S
+
+@@
+type T;
+statement S;
+expression V;
+@@
+
+V = (T *)isc_mem_get(...);
+- if (V == NULL) S
+
+@@
+statement S;
+expression V;
+@@
+
+if (V == NULL) V = isc_mem_get(...);
+- if (V == NULL) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+V = isc_mem_get(...);
+- if (V == NULL) S1 else { S2 }
++ S2
+
+@@
+type T;
+expression V, E1, E2;
+@@
+
+- V = (T)isc_mem_get(E1, E2);
++ V = isc_mem_get(E1, E2);
diff --git a/cocci/isc_mem_putanddetach.spatch b/cocci/isc_mem_putanddetach.spatch
new file mode 100644
index 0000000..0f29779
--- /dev/null
+++ b/cocci/isc_mem_putanddetach.spatch
@@ -0,0 +1,8 @@
+@@
+expression M;
+expression E1, E2;
+@@
+
+- isc_mem_put(M, E1, E2);
+- isc_mem_detach(&M);
++ isc_mem_putanddetach(&M, E1, E2);
diff --git a/cocci/isc_mem_strdup_never_fail.spatch b/cocci/isc_mem_strdup_never_fail.spatch
new file mode 100644
index 0000000..41cccdb
--- /dev/null
+++ b/cocci/isc_mem_strdup_never_fail.spatch
@@ -0,0 +1,33 @@
+@@
+statement S;
+expression V;
+@@
+
+V = isc_mem_strdup(...);
+- if (V == NULL) S
+
+@@
+type T;
+statement S;
+expression V;
+@@
+
+V = (T *)isc_mem_strdup(...);
+- if (V == NULL) S
+
+@@
+statement S;
+expression V;
+@@
+
+if (V == NULL) V = isc_mem_strdup(...);
+- if (V == NULL) S
+
+@@
+statement S1, S2;
+expression V;
+@@
+
+V = isc_mem_strdup(...);
+- if (V == NULL) S1 else { S2 }
++ S2
diff --git a/cocci/isc_mempool_create_cannot_fail.cocci b/cocci/isc_mempool_create_cannot_fail.cocci
new file mode 100644
index 0000000..f3509d2
--- /dev/null
+++ b/cocci/isc_mempool_create_cannot_fail.cocci
@@ -0,0 +1,49 @@
+@@
+expression V;
+@@
+
+- V =
+ isc_mempool_create(...);
+- assert_int_equal(V, ISC_R_SUCCESS);
+
+@@
+expression V;
+@@
+
+- V =
+ isc_mempool_create(...);
+- check_result(V, ...);
+
+@@
+@@
+
+- CHECK(
+ isc_mempool_create(...)
+- )
+ ;
+
+@@
+@@
+
+- RUNTIME_CHECK(
+ isc_mempool_create(...)
+- == ISC_R_SUCCESS)
+ ;
+
+@@
+expression V;
+statement S;
+@@
+
+- V =
+ isc_mempool_create(...);
+- if (V != ISC_R_SUCCESS) S
+
+@@
+statement S;
+@@
+
+- if (
+ isc_mempool_create(...)
+- != ISC_R_SUCCESS) S
++ ;
diff --git a/cocci/memcpy.spatch b/cocci/memcpy.spatch
new file mode 100644
index 0000000..f5e50e7
--- /dev/null
+++ b/cocci/memcpy.spatch
@@ -0,0 +1,14 @@
+@has_string_h@
+@@
+
+#include <string.h>
+
+@depends on has_string_h@
+
+expression D;
+expression S;
+expression N;
+@@
+
+- memcpy(D, S, N);
++ memmove(D, S, N);
diff --git a/cocci/null-the-pointer-early.disabled b/cocci/null-the-pointer-early.disabled
new file mode 100644
index 0000000..46fdffc
--- /dev/null
+++ b/cocci/null-the-pointer-early.disabled
@@ -0,0 +1,21 @@
+@@
+type T;
+T **PP;
+T *P;
+@@
+
+ P = *PP;
++ *PP = NULL;
+ ...
+- *PP = NULL;
+
+@@
+type T;
+identifier PP;
+identifier P;
+@@
+
+ T *P = *PP;
++ *PP = NULL;
+ ...
+- *PP = NULL;
diff --git a/cocci/return-void-from-void.spatch b/cocci/return-void-from-void.spatch
new file mode 100644
index 0000000..fcc639f
--- /dev/null
+++ b/cocci/return-void-from-void.spatch
@@ -0,0 +1,19 @@
+@ rule1 @
+identifier f1;
+@@
+
+void f1(...)
+{
+...
+}
+
+@ rule2 @
+identifier rule1.f1;
+identifier f2;
+@@
+
+void f2(...) {
+...
+* return(f1(...));
+...
+}
diff --git a/cocci/unreachable.spatch b/cocci/unreachable.spatch
new file mode 100644
index 0000000..84c0c34
--- /dev/null
+++ b/cocci/unreachable.spatch
@@ -0,0 +1,19 @@
+@@
+@@
+
+- INSIST(0);
++ UNREACHABLE();
+ ... when != UNREACHABLE();
+
+@@
+@@
+
+- INSIST(0);
+- ISC_UNREACHABLE();
++ UNREACHABLE();
+
+@@
+@@
+
+- UNREACHABLE();
+ UNREACHABLE();