Explorar o código

HPCC-21738 Can't ignore return value of fread

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman %!s(int64=6) %!d(string=hai) anos
pai
achega
c745e6e661
Modificáronse 1 ficheiros con 9 adicións e 2 borrados
  1. 9 2
      system/globalid/lnuid.cpp

+ 9 - 2
system/globalid/lnuid.cpp

@@ -40,6 +40,8 @@
 #include <sstream>
 #include <ctime>
 #include "lnuid.h"
+#include "jlog.hpp"
+
 using namespace std;
 
 namespace ln_uid {
@@ -87,8 +89,13 @@ namespace ln_uid {
 #if defined(__linux__) || defined(__APPLE__)
         FILE *fp;
         fp = fopen("/dev/urandom", "r");
-        fread(&randomdata, 1, random_byte_count, fp);
-        fclose(fp);
+        if (!fp || fread(&randomdata, 1, random_byte_count, fp) != random_byte_count)
+        {
+            // Should never happen, but if it does log it and ignore
+            OERRLOG("Could not read data from /dev/urandom");
+        }
+        if (fp)
+            fclose(fp);
 #elif _WIN32
         HCRYPTPROV hProvider;