[libc-commits] [PATCH] D147981: [LIBC] Fix `getrandom` success return value

Noah Goldstein via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Apr 12 11:46:04 PDT 2023


goldstein.w.n updated this revision to Diff 512924.
goldstein.w.n added a comment.

Test all sizes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147981/new/

https://reviews.llvm.org/D147981

Files:
  libc/src/sys/random/linux/getrandom.cpp
  libc/test/src/sys/random/linux/getrandom_test.cpp


Index: libc/test/src/sys/random/linux/getrandom_test.cpp
===================================================================
--- libc/test/src/sys/random/linux/getrandom_test.cpp
+++ libc/test/src/sys/random/linux/getrandom_test.cpp
@@ -29,6 +29,15 @@
   libc_errno = 0;
 }
 
+TEST(LlvmLibcGetRandomTest, ReturnsSize) {
+  static constexpr size_t SIZE = 8192;
+  uint8_t buf[SIZE];
+  for (size_t i = 0; i < SIZE; ++i) {
+    // Without GRND_RANDOM set this should never fail.
+    ASSERT_EQ(__llvm_libc::getrandom(buf, i, 0), static_cast<ssize_t>(i));
+  }
+}
+
 TEST(LlvmLibcGetRandomTest, PiEstimation) {
   static constexpr size_t LIMIT = 10000000;
   static constexpr double PI = 3.14159265358979;
Index: libc/src/sys/random/linux/getrandom.cpp
===================================================================
--- libc/src/sys/random/linux/getrandom.cpp
+++ libc/src/sys/random/linux/getrandom.cpp
@@ -23,7 +23,7 @@
     libc_errno = -ret;
     return -1;
   }
-  return 0;
+  return ret;
 }
 
 } // namespace __llvm_libc


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147981.512924.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230412/561bf6ca/attachment-0001.bin>


More information about the libc-commits mailing list