From 9b4805421eb2a7319f6507a26febfb9d2cdc3a93 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Apr 2019 12:43:47 +0200 Subject: [PATCH 1/2] lgtm: beef up list of dangerous/questionnable API calls not to make --- .../PotentiallyDangerousFunction.ql | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.lgtm/cpp-queries/PotentiallyDangerousFunction.ql b/.lgtm/cpp-queries/PotentiallyDangerousFunction.ql index ba80f4ad8c..cd0284b37a 100644 --- a/.lgtm/cpp-queries/PotentiallyDangerousFunction.ql +++ b/.lgtm/cpp-queries/PotentiallyDangerousFunction.ql @@ -16,10 +16,28 @@ import cpp predicate potentiallyDangerousFunction(Function f, string message) { ( f.getQualifiedName() = "fgets" and - message = "Call to fgets is potentially dangerous. Use read_line() instead." + message = "Call to fgets() is potentially dangerous. Use read_line() instead." ) or ( f.getQualifiedName() = "strtok" and - message = "Call to strtok is potentially dangerous. Use extract_first_word() instead." + message = "Call to strtok() is potentially dangerous. Use extract_first_word() instead." + ) or ( + f.getQualifiedName() = "strsep" and + message = "Call to strsep() is potentially dangerous. Use extract_first_word() instead." + ) or ( + f.getQualifiedName() = "dup" and + message = "Call to dup() is potentially dangerous. Use fcntl(fd, FD_DUPFD_CLOEXEC, 3) instead." + ) or ( + f.getQualifiedName() = "htonl" and + message = "Call to htonl() is confusing. Use htobe32() instead." + ) or ( + f.getQualifiedName() = "htons" and + message = "Call to htons() is confusing. Use htobe16() instead." + ) or ( + f.getQualifiedName() = "ntohl" and + message = "Call to ntohl() is confusing. Use be32toh() instead." + ) or ( + f.getQualifiedName() = "ntohs" and + message = "Call to ntohs() is confusing. Use be16toh() instead." ) } From f71611fed20aa73dea6350173aa4083d477d32ab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Apr 2019 12:44:15 +0200 Subject: [PATCH 2/2] test: stop using dup() needlessly --- src/login/test-inhibit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index a891b0af6f..7f9013bf93 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include +#include #include "sd-bus.h" @@ -30,7 +31,7 @@ static int inhibit(sd_bus *bus, const char *what) { assert_se(r >= 0); assert_se(fd >= 0); - return dup(fd); + return fcntl(fd, F_DUPFD_CLOEXEC, 3); } static void print_inhibitors(sd_bus *bus) {