Coverage Report

Created: 2024-11-21 07:03

/src/boringssl/crypto/rand_extra/forkunsafe.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2017, Google Inc.
2
 *
3
 * Permission to use, copy, modify, and/or distribute this software for any
4
 * purpose with or without fee is hereby granted, provided that the above
5
 * copyright notice and this permission notice appear in all copies.
6
 *
7
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15
#include <openssl/rand.h>
16
17
#include <stdlib.h>
18
19
#include "../fipsmodule/rand/internal.h"
20
#include "../internal.h"
21
22
23
// g_buffering_enabled is one if fork-unsafe buffering has been enabled and zero
24
// otherwise.
25
static CRYPTO_atomic_u32 g_buffering_enabled = 0;
26
27
#if !defined(OPENSSL_WINDOWS)
28
0
void RAND_enable_fork_unsafe_buffering(int fd) {
29
  // We no longer support setting the file-descriptor with this function.
30
0
  if (fd != -1) {
31
0
    abort();
32
0
  }
33
34
0
  CRYPTO_atomic_store_u32(&g_buffering_enabled, 1);
35
0
}
36
37
0
void RAND_disable_fork_unsafe_buffering(void) {
38
0
  CRYPTO_atomic_store_u32(&g_buffering_enabled, 0);
39
0
}
40
#endif
41
42
4.28k
int rand_fork_unsafe_buffering_enabled(void) {
43
4.28k
  return CRYPTO_atomic_load_u32(&g_buffering_enabled) != 0;
44
4.28k
}