Skip to content

Commit a40c3e2

Browse files
laramielcopybara-github
authored andcommitted
Log on RAND_bytes failure
In boringssl this should never happen, but according to documentation it's possible with openssl and similar implementations. PiperOrigin-RevId: 749907740 Change-Id: I2de077d910a8267bc1563c4153b9370b44bec530
1 parent 74a8876 commit a40c3e2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

python/tensorstore/status.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "absl/status/status.h"
3030
#include "absl/strings/cord.h"
3131
#include <openssl/crypto.h>
32+
#include <openssl/err.h>
3233
#include <openssl/evp.h>
3334
#include <openssl/hmac.h>
3435
#include <openssl/rand.h>
@@ -59,7 +60,14 @@ namespace py = ::pybind11;
5960
/// but unpickling legitimate exception values is unlikely to have harmful
6061
/// side effects.
6162
struct StatusPayloadKeys {
62-
StatusPayloadKeys() { ABSL_CHECK_EQ(1, RAND_bytes(keys, kTotalKeyLength)); }
63+
StatusPayloadKeys() {
64+
if (int success = RAND_bytes(keys, kTotalKeyLength); success != 1) {
65+
// Only some implementations of RAND_bytes fail; if so, log a fatal error.
66+
char buf[256];
67+
ERR_error_string_n(ERR_get_error(), buf, sizeof(buf));
68+
ABSL_CHECK_EQ(success, 1) << "RAND_bytes " << buf;
69+
}
70+
}
6371

6472
/// Size of key used as the payload identifier.
6573
constexpr static size_t kPayloadIdSize = 32;

0 commit comments

Comments
 (0)