From 16588f3bc15fa6096d2ff6c5968ac3e2fc20ea61 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 21 Sep 2020 10:22:55 +0200 Subject: [PATCH] Check return value of dup(2) as noted by coverity. --- pdns/rec_channel_rec.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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) -- 2.47.2