From: Otto Moerbeek Date: Mon, 21 Sep 2020 08:22:55 +0000 (+0200) Subject: Check return value of dup(2) as noted by coverity. X-Git-Tag: auth-4.4.0-alpha1~21^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9490%2Fhead;p=thirdparty%2Fpdns.git Check return value of dup(2) as noted by coverity. --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index f9faa477cd..3161314c86 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -201,14 +201,16 @@ string static doGetParameter(T begin, T end) static uint64_t dumpNegCache(int fd) { - auto fp = std::unique_ptr(fdopen(dup(fd), "w"), fclose); - if(!fp) { // dup probably failed + int newfd = dup(fd); + if (newfd == -1) { + return 0; + } + auto fp = std::unique_ptr(fdopen(newfd, "w"), fclose); + if (!fp) { return 0; } - uint64_t ret; fprintf(fp.get(), "; negcache dump follows\n;\n"); - ret = g_negCache->dumpToFile(fp.get()); - return ret; + return g_negCache->dumpToFile(fp.get()); } static uint64_t* pleaseDump(int fd)