From: Nick Mathewson Date: Thu, 17 Apr 2025 23:17:26 +0000 (-0400) Subject: Abolish RELAY_HEADER_SIZE. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d6162374ae1f5c06ddd6fa721197d2966bde71b;p=thirdparty%2Ftor.git Abolish RELAY_HEADER_SIZE. It was frequently used before to index into a cell, which is never right any more. --- diff --git a/src/core/or/or.h b/src/core/or/or.h index 3e18d65bbd..57d5d3e694 100644 --- a/src/core/or/or.h +++ b/src/core/or/or.h @@ -553,9 +553,8 @@ static inline int get_circ_id_size(int wide_circ_ids) /* TODO #41051: It would be better if these went away. */ /** Number of bytes in a relay cell's header (not including general cell * header). */ -#define RELAY_HEADER_SIZE (1+2+2+4+2) /** Largest number of bytes that can fit in a relay cell payload. */ -#define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE) +#define RELAY_PAYLOAD_SIZE (CELL_PAYLOAD_SIZE-(1+2+2+4+2)) /** Number of bytes used for a relay cell's header, in the v0 format. */ #define RELAY_HEADER_SIZE_V0 (1+2+2+4+2) diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c index 178aec2ab2..b46726aa4a 100644 --- a/src/test/test_cell_formats.c +++ b/src/test/test_cell_formats.c @@ -33,12 +33,12 @@ static void test_cfmt_relay_header(void *arg) { relay_header_t rh; - const uint8_t hdr_1[RELAY_HEADER_SIZE] = + const uint8_t hdr_1[RELAY_HEADER_SIZE_V0] = "\x03" "\x00\x00" "\x21\x22" "ABCD" "\x01\x03"; - uint8_t hdr_out[RELAY_HEADER_SIZE]; + uint8_t hdr_out[RELAY_HEADER_SIZE_V0]; (void)arg; - tt_int_op(sizeof(hdr_1), OP_EQ, RELAY_HEADER_SIZE); + tt_int_op(sizeof(hdr_1), OP_EQ, RELAY_HEADER_SIZE_V0); relay_header_unpack(&rh, hdr_1); tt_int_op(rh.command, OP_EQ, 3); tt_int_op(rh.recognized, OP_EQ, 0); @@ -47,7 +47,7 @@ test_cfmt_relay_header(void *arg) tt_int_op(rh.length, OP_EQ, 0x103); relay_header_pack(hdr_out, &rh); - tt_mem_op(hdr_out, OP_EQ, hdr_1, RELAY_HEADER_SIZE); + tt_mem_op(hdr_out, OP_EQ, hdr_1, RELAY_HEADER_SIZE_V0); done: ;