naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
be0c12
From 42123e9614ea73c7f64c684c90e4dbb049ef67ef Mon Sep 17 00:00:00 2001
be0c12
From: Frantisek Sumsal <frantisek@sumsal.cz>
be0c12
Date: Sun, 5 Dec 2021 10:25:28 +0100
be0c12
Subject: [PATCH] lgtm: ignore certain cleanup functions
be0c12
be0c12
as they don't do any illegal stuff even when used with an uninitialized
be0c12
variable.
be0c12
be0c12
(cherry picked from commit af1868213657b38b8d4008608976eb81546cfb8e)
be0c12
be0c12
Related: #2017033
be0c12
---
be0c12
 .lgtm/cpp-queries/UninitializedVariableWithCleanup.ql | 9 +++++++++
be0c12
 1 file changed, 9 insertions(+)
be0c12
be0c12
diff --git a/.lgtm/cpp-queries/UninitializedVariableWithCleanup.ql b/.lgtm/cpp-queries/UninitializedVariableWithCleanup.ql
be0c12
index 6bf0ae01eb..8c24b6d8f1 100644
be0c12
--- a/.lgtm/cpp-queries/UninitializedVariableWithCleanup.ql
be0c12
+++ b/.lgtm/cpp-queries/UninitializedVariableWithCleanup.ql
be0c12
@@ -34,6 +34,13 @@ predicate allocatedType(Type t) {
be0c12
   allocatedType(t.getUnspecifiedType())
be0c12
 }
be0c12
 
be0c12
+/** Auxiliary predicate: List cleanup functions we want to explicitly ignore
be0c12
+  * since they don't do anything illegal even when the variable is uninitialized
be0c12
+  */
be0c12
+predicate cleanupFunctionDenyList(string fun) {
be0c12
+  fun = "erase_char"
be0c12
+}
be0c12
+
be0c12
 /**
be0c12
  * A declaration of a local variable using __attribute__((__cleanup__(x)))
be0c12
  * that leaves the variable uninitialized.
be0c12
@@ -43,6 +50,8 @@ DeclStmt declWithNoInit(LocalVariable v) {
be0c12
   not exists(v.getInitializer()) and
be0c12
   /* The variable has __attribute__((__cleanup__(...))) set */
be0c12
   v.getAnAttribute().hasName("cleanup") and
be0c12
+  /* Check if the cleanup function is not on a deny list */
be0c12
+  not exists(Attribute a | a = v.getAnAttribute() and a.getName() = "cleanup" | cleanupFunctionDenyList(a.getAnArgument().getValueText())) and
be0c12
   /* The type of the variable is not stack-allocated. */
be0c12
   exists(Type t | t = v.getType() | not allocatedType(t))
be0c12
 }