mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
rename inherit values to avoid conflict with system defines
This commit is contained in:
parent
785c3f84de
commit
027c536598
@ -152,7 +152,7 @@ crypto_fast_rng_new(void)
|
|||||||
crypto_fast_rng_t *
|
crypto_fast_rng_t *
|
||||||
crypto_fast_rng_new_from_seed(const uint8_t *seed)
|
crypto_fast_rng_new_from_seed(const uint8_t *seed)
|
||||||
{
|
{
|
||||||
unsigned inherit = INHERIT_KEEP;
|
unsigned inherit = INHERIT_RES_KEEP;
|
||||||
/* We try to allocate this object as securely as we can, to avoid
|
/* We try to allocate this object as securely as we can, to avoid
|
||||||
* having it get dumped, swapped, or shared after fork.
|
* having it get dumped, swapped, or shared after fork.
|
||||||
*/
|
*/
|
||||||
@ -164,7 +164,7 @@ crypto_fast_rng_new_from_seed(const uint8_t *seed)
|
|||||||
result->bytes_left = 0;
|
result->bytes_left = 0;
|
||||||
result->n_till_reseed = RESEED_AFTER;
|
result->n_till_reseed = RESEED_AFTER;
|
||||||
#ifdef CHECK_PID
|
#ifdef CHECK_PID
|
||||||
if (inherit == INHERIT_KEEP) {
|
if (inherit == INHERIT_RES_KEEP) {
|
||||||
/* This value will neither be dropped nor zeroed after fork, so we need to
|
/* This value will neither be dropped nor zeroed after fork, so we need to
|
||||||
* check our pid to make sure we are not sharing it across a fork. This
|
* check our pid to make sure we are not sharing it across a fork. This
|
||||||
* can be expensive if the pid value isn't cached, sadly.
|
* can be expensive if the pid value isn't cached, sadly.
|
||||||
@ -176,7 +176,7 @@ crypto_fast_rng_new_from_seed(const uint8_t *seed)
|
|||||||
#else
|
#else
|
||||||
/* We decided above that noinherit would always do _something_. Assert here
|
/* We decided above that noinherit would always do _something_. Assert here
|
||||||
* that we were correct. */
|
* that we were correct. */
|
||||||
tor_assert(inherit != INHERIT_KEEP);
|
tor_assert(inherit != INHERIT_RES_KEEP);
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -253,12 +253,12 @@ crypto_fast_rng_getbytes_impl(crypto_fast_rng_t *rng, uint8_t *out,
|
|||||||
if (rng->owner) {
|
if (rng->owner) {
|
||||||
/* Note that we only need to do this check when we have owner set: that
|
/* Note that we only need to do this check when we have owner set: that
|
||||||
* is, when our attempt to block inheriting failed, and the result was
|
* is, when our attempt to block inheriting failed, and the result was
|
||||||
* INHERIT_KEEP.
|
* INHERIT_RES_KEEP.
|
||||||
*
|
*
|
||||||
* If the result was INHERIT_DROP, then any attempt to access the rng
|
* If the result was INHERIT_RES_DROP, then any attempt to access the rng
|
||||||
* memory after forking will crash.
|
* memory after forking will crash.
|
||||||
*
|
*
|
||||||
* If the result was INHERIT_ZERO, then forking will set the bytes_left
|
* If the result was INHERIT_RES_ZERO, then forking will set the bytes_left
|
||||||
* and n_till_reseed fields to zero. This function will call
|
* and n_till_reseed fields to zero. This function will call
|
||||||
* crypto_fast_rng_refill(), which will in turn reseed the PRNG.
|
* crypto_fast_rng_refill(), which will in turn reseed the PRNG.
|
||||||
*
|
*
|
||||||
|
@ -123,14 +123,14 @@ noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out)
|
|||||||
#ifdef FLAG_ZERO
|
#ifdef FLAG_ZERO
|
||||||
int r = MINHERIT(mem, sz, FLAG_ZERO);
|
int r = MINHERIT(mem, sz, FLAG_ZERO);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
*inherit_result_out = INHERIT_ZERO;
|
*inherit_result_out = INHERIT_RES_ZERO;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef FLAG_NOINHERIT
|
#ifdef FLAG_NOINHERIT
|
||||||
int r2 = MINHERIT(mem, sz, FLAG_NOINHERIT);
|
int r2 = MINHERIT(mem, sz, FLAG_NOINHERIT);
|
||||||
if (r2 == 0) {
|
if (r2 == 0) {
|
||||||
*inherit_result_out = INHERIT_DROP;
|
*inherit_result_out = INHERIT_RES_DROP;
|
||||||
}
|
}
|
||||||
return r2;
|
return r2;
|
||||||
#else
|
#else
|
||||||
@ -154,9 +154,9 @@ noinherit_mem(void *mem, size_t sz, unsigned *inherit_result_out)
|
|||||||
* Memory returned from this function must be released with
|
* Memory returned from this function must be released with
|
||||||
* tor_munmap_anonymous().
|
* tor_munmap_anonymous().
|
||||||
*
|
*
|
||||||
* If <b>inherit_result_out</b> is non-NULL, set it to one of INHERIT_KEEP,
|
* If <b>inherit_result_out</b> is non-NULL, set it to one of
|
||||||
* INHERIT_DROP, and INHERIT_ZERO, depending on the properties of the returned
|
* INHERIT_RES_KEEP, INHERIT_RES_DROP, or INHERIT_RES_ZERO, depending on the
|
||||||
* memory.
|
* properties of the returned memory.
|
||||||
*
|
*
|
||||||
* [Note: OS people use the word "anonymous" here to mean that the memory
|
* [Note: OS people use the word "anonymous" here to mean that the memory
|
||||||
* isn't associated with any file. This has *nothing* to do with the kind of
|
* isn't associated with any file. This has *nothing* to do with the kind of
|
||||||
@ -170,7 +170,7 @@ tor_mmap_anonymous(size_t sz, unsigned flags, unsigned *inherit_result_out)
|
|||||||
if (inherit_result_out == NULL) {
|
if (inherit_result_out == NULL) {
|
||||||
inherit_result_out = &itmp;
|
inherit_result_out = &itmp;
|
||||||
}
|
}
|
||||||
*inherit_result_out = INHERIT_KEEP;
|
*inherit_result_out = INHERIT_RES_KEEP;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE,
|
HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE,
|
||||||
|
@ -33,13 +33,13 @@
|
|||||||
|
|
||||||
/** Possible value for inherit_result_out: the memory will be kept
|
/** Possible value for inherit_result_out: the memory will be kept
|
||||||
* by any child process. */
|
* by any child process. */
|
||||||
#define INHERIT_KEEP 0
|
#define INHERIT_RES_KEEP 0
|
||||||
/** Possible value for inherit_result_out: the memory will be dropped in
|
/** Possible value for inherit_result_out: the memory will be dropped in
|
||||||
* the child process. Attempting to access it will likely cause a segfault. */
|
* the child process. Attempting to access it will likely cause a segfault. */
|
||||||
#define INHERIT_DROP 1
|
#define INHERIT_RES_DROP 1
|
||||||
/** Possible value for inherit_result_out: the memory will be cleared in
|
/** Possible value for inherit_result_out: the memory will be cleared in
|
||||||
* the child process. */
|
* the child process. */
|
||||||
#define INHERIT_ZERO 2
|
#define INHERIT_RES_ZERO 2
|
||||||
|
|
||||||
/* Here we define the NOINHERIT_CAN_FAIL macro if and only if
|
/* Here we define the NOINHERIT_CAN_FAIL macro if and only if
|
||||||
* it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
|
* it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
|
||||||
|
@ -6135,7 +6135,7 @@ test_util_map_anon(void *arg)
|
|||||||
/* Basic checks. */
|
/* Basic checks. */
|
||||||
ptr = tor_mmap_anonymous(sz, 0, &inherit);
|
ptr = tor_mmap_anonymous(sz, 0, &inherit);
|
||||||
tt_ptr_op(ptr, OP_NE, 0);
|
tt_ptr_op(ptr, OP_NE, 0);
|
||||||
tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
|
tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
|
||||||
ptr[sz-1] = 3;
|
ptr[sz-1] = 3;
|
||||||
tt_int_op(ptr[0], OP_EQ, 0);
|
tt_int_op(ptr[0], OP_EQ, 0);
|
||||||
tt_int_op(ptr[sz-2], OP_EQ, 0);
|
tt_int_op(ptr[sz-2], OP_EQ, 0);
|
||||||
@ -6145,7 +6145,7 @@ test_util_map_anon(void *arg)
|
|||||||
tor_munmap_anonymous(ptr, sz);
|
tor_munmap_anonymous(ptr, sz);
|
||||||
ptr = tor_mmap_anonymous(sz, ANONMAP_PRIVATE, &inherit);
|
ptr = tor_mmap_anonymous(sz, ANONMAP_PRIVATE, &inherit);
|
||||||
tt_ptr_op(ptr, OP_NE, 0);
|
tt_ptr_op(ptr, OP_NE, 0);
|
||||||
tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
|
tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
|
||||||
ptr[sz-1] = 10;
|
ptr[sz-1] = 10;
|
||||||
tt_int_op(ptr[0], OP_EQ, 0);
|
tt_int_op(ptr[0], OP_EQ, 0);
|
||||||
tt_int_op(ptr[sz/2], OP_EQ, 0);
|
tt_int_op(ptr[sz/2], OP_EQ, 0);
|
||||||
@ -6207,16 +6207,16 @@ test_util_map_anon_nofork(void *arg)
|
|||||||
char buf[1];
|
char buf[1];
|
||||||
ssize_t r = read(pipefd[0], buf, 1);
|
ssize_t r = read(pipefd[0], buf, 1);
|
||||||
|
|
||||||
if (inherit == INHERIT_ZERO) {
|
if (inherit == INHERIT_RES_ZERO) {
|
||||||
// We should be seeing clear-on-fork behavior.
|
// We should be seeing clear-on-fork behavior.
|
||||||
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
|
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
|
||||||
tt_int_op(buf[0], OP_EQ, 0); // that byte should be zero.
|
tt_int_op(buf[0], OP_EQ, 0); // that byte should be zero.
|
||||||
} else if (inherit == INHERIT_DROP) {
|
} else if (inherit == INHERIT_RES_DROP) {
|
||||||
// We should be seeing noinherit behavior.
|
// We should be seeing noinherit behavior.
|
||||||
tt_int_op(r, OP_LE, 0); // child said nothing; it should have crashed.
|
tt_int_op(r, OP_LE, 0); // child said nothing; it should have crashed.
|
||||||
} else {
|
} else {
|
||||||
// noinherit isn't implemented.
|
// noinherit isn't implemented.
|
||||||
tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
|
tt_int_op(inherit, OP_EQ, INHERIT_RES_KEEP);
|
||||||
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
|
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
|
||||||
tt_int_op(buf[0], OP_EQ, 0xd0); // that byte should what we set it to.
|
tt_int_op(buf[0], OP_EQ, 0xd0); // that byte should what we set it to.
|
||||||
}
|
}
|
||||||
@ -6227,9 +6227,9 @@ test_util_map_anon_nofork(void *arg)
|
|||||||
#ifndef NOINHERIT_CAN_FAIL
|
#ifndef NOINHERIT_CAN_FAIL
|
||||||
/* Only if NOINHERIT_CAN_FAIL should it be possible for us to get
|
/* Only if NOINHERIT_CAN_FAIL should it be possible for us to get
|
||||||
* INHERIT_KEEP behavior in this case. */
|
* INHERIT_KEEP behavior in this case. */
|
||||||
tt_assert(inherit, OP_NE, INHERIT_KEEP);
|
tt_assert(inherit, OP_NE, INHERIT_RES_KEEP);
|
||||||
#else
|
#else
|
||||||
if (inherit == INHERIT_KEEP) {
|
if (inherit == INHERIT_RES_KEEP) {
|
||||||
/* Call this test "skipped", not "passed", since noinherit wasn't
|
/* Call this test "skipped", not "passed", since noinherit wasn't
|
||||||
* implemented. */
|
* implemented. */
|
||||||
tt_skip();
|
tt_skip();
|
||||||
|
Loading…
Reference in New Issue
Block a user