daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ff6046
From c9fdcd0693ac63bc4b7326e248854617d9573bd6 Mon Sep 17 00:00:00 2001
ff6046
From: Evgeny Vereshchagin <evvers@ya.ru>
ff6046
Date: Fri, 26 Oct 2018 09:19:09 +0000
ff6046
Subject: [PATCH] lgtm: add a custom query for catching the use of fgets
ff6046
ff6046
As everybody knows, nodoby really reads CODING_STYLE (especially
ff6046
the last paragraph :-)) so let's utilize LGTM to help us catch the
ff6046
use of fgets.
ff6046
ff6046
(cherry picked from commit f86c1da28340f2a2afd34d72c9f416a2a94219a8)
ff6046
---
ff6046
 .lgtm/cpp-queries/fgets.ql | 23 +++++++++++++++++++++++
ff6046
 1 file changed, 23 insertions(+)
ff6046
 create mode 100644 .lgtm/cpp-queries/fgets.ql
ff6046
ff6046
diff --git a/.lgtm/cpp-queries/fgets.ql b/.lgtm/cpp-queries/fgets.ql
ff6046
new file mode 100644
ff6046
index 0000000000..82de8c4482
ff6046
--- /dev/null
ff6046
+++ b/.lgtm/cpp-queries/fgets.ql
ff6046
@@ -0,0 +1,23 @@
ff6046
+/**
ff6046
+ * @name Use of fgets()
ff6046
+ * @description fgets() is dangerous to call. Use read_line() instead.
ff6046
+ * @kind problem
ff6046
+ * @problem.severity error
ff6046
+ * @precision high
ff6046
+ * @id cpp/fgets
ff6046
+ * @tags reliability
ff6046
+ *       security
ff6046
+ */
ff6046
+import cpp
ff6046
+
ff6046
+
ff6046
+predicate dangerousFunction(Function function) {
ff6046
+  exists (string name | name = function.getQualifiedName() |
ff6046
+    name = "fgets")
ff6046
+}
ff6046
+
ff6046
+
ff6046
+from FunctionCall call, Function target
ff6046
+where call.getTarget() = target
ff6046
+  and dangerousFunction(target)
ff6046
+select call, target.getQualifiedName() + " is potentially dangerous"