]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Check return value of dup(2) as noted by coverity. 9490/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 21 Sep 2020 08:22:55 +0000 (10:22 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 22 Sep 2020 09:19:47 +0000 (11:19 +0200)
pdns/rec_channel_rec.cc

index f9faa477cd0424d10fd09cd1442d549d6a66017f..3161314c8600ba2d7c87a7a175145e4060422ca6 100644 (file)
@@ -201,14 +201,16 @@ string static doGetParameter(T begin, T end)
 
 static uint64_t dumpNegCache(int fd)
 {
-  auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(fdopen(dup(fd), "w"), fclose);
-  if(!fp) { // dup probably failed
+  int newfd = dup(fd);
+  if (newfd == -1) {
+    return 0;
+  }
+  auto fp = std::unique_ptr<FILE, int(*)(FILE*)>(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)