ryantimwilson / rpms / systemd

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