mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Use size_t for length in replaycache_add_test_and_elapsed()
For consistency with the rest of buffer lengths in Tor. See #8960
This commit is contained in:
parent
468e44a0ef
commit
506a01bda8
@ -1207,7 +1207,7 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
|
||||
/* check for replay of PK-encrypted portion. */
|
||||
replay = replaycache_add_test_and_elapsed(
|
||||
intro_point->accepted_intro_rsa_parts,
|
||||
parsed_req->ciphertext, (int)parsed_req->ciphertext_len,
|
||||
parsed_req->ciphertext, parsed_req->ciphertext_len,
|
||||
&elapsed);
|
||||
|
||||
if (replay) {
|
||||
|
@ -65,7 +65,7 @@ replaycache_new(time_t horizon, time_t interval)
|
||||
|
||||
STATIC int
|
||||
replaycache_add_and_test_internal(
|
||||
time_t present, replaycache_t *r, const void *data, int len,
|
||||
time_t present, replaycache_t *r, const void *data, size_t len,
|
||||
time_t *elapsed)
|
||||
{
|
||||
int rv = 0;
|
||||
@ -73,7 +73,7 @@ replaycache_add_and_test_internal(
|
||||
time_t *access_time;
|
||||
|
||||
/* sanity check */
|
||||
if (present <= 0 || !r || !data || len <= 0) {
|
||||
if (present <= 0 || !r || !data || len == 0) {
|
||||
log_info(LD_BUG, "replaycache_add_and_test_internal() called with stupid"
|
||||
" parameters; please fix this.");
|
||||
goto done;
|
||||
@ -176,7 +176,7 @@ replaycache_scrub_if_needed_internal(time_t present, replaycache_t *r)
|
||||
*/
|
||||
|
||||
int
|
||||
replaycache_add_and_test(replaycache_t *r, const void *data, int len)
|
||||
replaycache_add_and_test(replaycache_t *r, const void *data, size_t len)
|
||||
{
|
||||
return replaycache_add_and_test_internal(time(NULL), r, data, len, NULL);
|
||||
}
|
||||
@ -187,7 +187,7 @@ replaycache_add_and_test(replaycache_t *r, const void *data, int len)
|
||||
|
||||
int
|
||||
replaycache_add_test_and_elapsed(
|
||||
replaycache_t *r, const void *data, int len, time_t *elapsed)
|
||||
replaycache_t *r, const void *data, size_t len, time_t *elapsed)
|
||||
{
|
||||
return replaycache_add_and_test_internal(time(NULL), r, data, len, elapsed);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ replaycache_t * replaycache_new(time_t horizon, time_t interval);
|
||||
*/
|
||||
|
||||
STATIC int replaycache_add_and_test_internal(
|
||||
time_t present, replaycache_t *r, const void *data, int len,
|
||||
time_t present, replaycache_t *r, const void *data, size_t len,
|
||||
time_t *elapsed);
|
||||
STATIC void replaycache_scrub_if_needed_internal(
|
||||
time_t present, replaycache_t *r);
|
||||
@ -57,9 +57,9 @@ STATIC void replaycache_scrub_if_needed_internal(
|
||||
* replaycache_t methods
|
||||
*/
|
||||
|
||||
int replaycache_add_and_test(replaycache_t *r, const void *data, int len);
|
||||
int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
|
||||
int replaycache_add_test_and_elapsed(
|
||||
replaycache_t *r, const void *data, int len, time_t *elapsed);
|
||||
replaycache_t *r, const void *data, size_t len, time_t *elapsed);
|
||||
void replaycache_scrub_if_needed(replaycache_t *r);
|
||||
|
||||
#endif
|
||||
|
@ -76,13 +76,13 @@ test_replaycache_miss(void)
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
/* poke the bad-parameter error case too */
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, NULL, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
done:
|
||||
@ -102,12 +102,12 @@ test_replaycache_hit(void)
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1300, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 1);
|
||||
|
||||
done:
|
||||
@ -127,17 +127,17 @@ test_replaycache_age(void)
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1300, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 1);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(3000, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
done:
|
||||
@ -158,12 +158,12 @@ test_replaycache_elapsed(void)
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1300, r, test_buffer,
|
||||
(int)strlen(test_buffer), &elapsed);
|
||||
strlen(test_buffer), &elapsed);
|
||||
test_eq(result, 1);
|
||||
test_eq(elapsed, 100);
|
||||
|
||||
@ -184,17 +184,17 @@ test_replaycache_noexpire(void)
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(1300, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 1);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(3000, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 1);
|
||||
|
||||
done:
|
||||
@ -215,12 +215,12 @@ test_replaycache_scrub(void)
|
||||
/* Set up like in test_replaycache_hit() */
|
||||
result =
|
||||
replaycache_add_and_test_internal(100, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(200, r, test_buffer,
|
||||
(int)strlen(test_buffer), NULL);
|
||||
strlen(test_buffer), NULL);
|
||||
test_eq(result, 1);
|
||||
|
||||
/*
|
||||
@ -257,14 +257,14 @@ test_replaycache_future(void)
|
||||
/* Set up like in test_replaycache_hit() */
|
||||
result =
|
||||
replaycache_add_and_test_internal(100, r, test_buffer,
|
||||
(int)strlen(test_buffer), &elapsed);
|
||||
strlen(test_buffer), &elapsed);
|
||||
test_eq(result, 0);
|
||||
/* elapsed should still be 0, since it wasn't written */
|
||||
test_eq(elapsed, 0);
|
||||
|
||||
result =
|
||||
replaycache_add_and_test_internal(200, r, test_buffer,
|
||||
(int)strlen(test_buffer), &elapsed);
|
||||
strlen(test_buffer), &elapsed);
|
||||
test_eq(result, 1);
|
||||
/* elapsed should be the time since the last hit */
|
||||
test_eq(elapsed, 100);
|
||||
@ -275,7 +275,7 @@ test_replaycache_future(void)
|
||||
*/
|
||||
result =
|
||||
replaycache_add_and_test_internal(150, r, test_buffer,
|
||||
(int)strlen(test_buffer), &elapsed);
|
||||
strlen(test_buffer), &elapsed);
|
||||
/* We should still get a hit */
|
||||
test_eq(result, 1);
|
||||
/* ...but it shouldn't let us see a negative elapsed time */
|
||||
@ -304,18 +304,18 @@ test_replaycache_realtime(void)
|
||||
|
||||
/* This should miss */
|
||||
result =
|
||||
replaycache_add_and_test(r, test_buffer, (int)strlen(test_buffer));
|
||||
replaycache_add_and_test(r, test_buffer, strlen(test_buffer));
|
||||
test_eq(result, 0);
|
||||
|
||||
/* This should hit */
|
||||
result =
|
||||
replaycache_add_and_test(r, test_buffer, (int)strlen(test_buffer));
|
||||
replaycache_add_and_test(r, test_buffer, strlen(test_buffer));
|
||||
test_eq(result, 1);
|
||||
|
||||
/* This should hit and return a small elapsed time */
|
||||
result =
|
||||
replaycache_add_test_and_elapsed(r, test_buffer,
|
||||
(int)strlen(test_buffer), &elapsed);
|
||||
strlen(test_buffer), &elapsed);
|
||||
test_eq(result, 1);
|
||||
test_assert(elapsed >= 0);
|
||||
test_assert(elapsed <= 5);
|
||||
|
Loading…
Reference in New Issue
Block a user