From 3cd59fe6ad0622af844578243b6fc34d1669a571 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Dec 15 2020 09:45:29 +0000 Subject: lgtm: add a custom query for catching the use of fgets 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. (cherry picked from commit f86c1da28340f2a2afd34d72c9f416a2a94219a8) patch_name: 0095-lgtm-add-a-custom-query-for-catching-the-use-of-fget.patch present_in_specfile: true location_in_specfile: 95 squash_commits: true --- diff --git a/.lgtm/cpp-queries/fgets.ql b/.lgtm/cpp-queries/fgets.ql new file mode 100644 index 0000000..82de8c4 --- /dev/null +++ b/.lgtm/cpp-queries/fgets.ql @@ -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"