]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
lgtm: add a custom query for catching the use of fgets
authorEvgeny Vereshchagin <evvers@ya.ru>
Fri, 26 Oct 2018 09:19:09 +0000 (09:19 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 10:27:43 +0000 (12:27 +0200)
As everybody knows, nodoby really reads CODING_STYLE (especially
the last paragraph :-)) so let's utilize LGTM to help us catch the
use of fgets.

.lgtm/cpp-queries/fgets.ql [new file with mode: 0644]

diff --git a/.lgtm/cpp-queries/fgets.ql b/.lgtm/cpp-queries/fgets.ql
new file mode 100644 (file)
index 0000000..82de8c4
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * @name Use of fgets()
+ * @description fgets() is dangerous to call. Use read_line() instead.
+ * @kind problem
+ * @problem.severity error
+ * @precision high
+ * @id cpp/fgets
+ * @tags reliability
+ *       security
+ */
+import cpp
+
+
+predicate dangerousFunction(Function function) {
+  exists (string name | name = function.getQualifiedName() |
+    name = "fgets")
+}
+
+
+from FunctionCall call, Function target
+where call.getTarget() = target
+  and dangerousFunction(target)
+select call, target.getQualifiedName() + " is potentially dangerous"