]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
relay_msg: use IF_BUG_ONCE
authorNick Mathewson <nickm@torproject.org>
Thu, 17 Apr 2025 23:20:37 +0000 (19:20 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 5 May 2025 17:07:37 +0000 (13:07 -0400)
If these bugs are reachable, they're likely to fill up the logs.

src/core/or/relay_msg.c

index 5b40a680579081aad55fa97eef202b266c977e9a..f6f7a207b2c6d82200c1e4f4c09796e1508dbfbd 100644 (file)
@@ -115,8 +115,9 @@ static int
 encode_v0_cell(const relay_msg_t *msg,
                cell_t *cell_out)
 {
-  if (BUG(msg->length > CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V0))
+  IF_BUG_ONCE(msg->length > CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V0) {
     return -1;
+  }
 
   uint8_t *out = cell_out->payload;
 
@@ -143,21 +144,23 @@ encode_v1_cell(const relay_msg_t *msg,
     maxlen = CELL_PAYLOAD_SIZE - RELAY_HEADER_SIZE_V1_NO_STREAM_ID;
   }
 
-  if (BUG(msg->length > maxlen))
+  IF_BUG_ONCE(msg->length > maxlen) {
     return -1;
-
+  }
   uint8_t *out = cell_out->payload;
   out[V1_CMD_OFFSET] = msg->command;
   set_uint16(out+V1_LEN_OFFSET, htons(msg->length));
   size_t payload_offset;
   if (expects_streamid) {
-    if (BUG(msg->stream_id == 0))
+    IF_BUG_ONCE(msg->stream_id == 0) {
       return -1;
+    }
     set_uint16(out+V1_STREAM_ID_OFFSET, htons(msg->stream_id));
     payload_offset = V1_PAYLOAD_OFFSET_WITH_STREAM_ID;
   } else {
-    if (BUG(msg->stream_id != 0))
+    IF_BUG_ONCE(msg->stream_id != 0) {
       return -1;
+    }
 
     payload_offset = V1_PAYLOAD_OFFSET_NO_STREAM_ID;
   }