Browse Source

Replace buf->datalen usage in proto_*.c with buf_datalen() call.

This lets us remove BUFFERS_PRIVATE from two of the modules.
Nick Mathewson 6 years ago
parent
commit
cddac959e7
4 changed files with 12 additions and 14 deletions
  1. 2 3
      src/or/proto_cell.c
  2. 1 2
      src/or/proto_control0.c
  3. 2 2
      src/or/proto_http.c
  4. 7 7
      src/or/proto_socks.c

+ 2 - 3
src/or/proto_cell.c

@@ -4,7 +4,6 @@
  * Copyright (c) 2007-2017, The Tor Project, Inc. */
 /* See LICENSE for licensing information */
 
-#define BUFFERS_PRIVATE // XXXX remove.
 #include "or.h"
 #include "buffers.h"
 #include "proto_cell.h"
@@ -56,7 +55,7 @@ fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto)
   const int circ_id_len = get_circ_id_size(wide_circ_ids);
   const unsigned header_len = get_var_cell_header_size(wide_circ_ids);
   *out = NULL;
-  if (buf->datalen < header_len)
+  if (buf_datalen(buf) < header_len)
     return 0;
   peek_from_buf(hdr, header_len, buf);
 
@@ -65,7 +64,7 @@ fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto)
     return 0;
 
   length = ntohs(get_uint16(hdr + circ_id_len + 1));
-  if (buf->datalen < (size_t)(header_len+length))
+  if (buf_datalen(buf) < (size_t)(header_len+length))
     return 1;
   result = var_cell_new(length);
   result->command = command;

+ 1 - 2
src/or/proto_control0.c

@@ -4,7 +4,6 @@
  * Copyright (c) 2007-2017, The Tor Project, Inc. */
 /* See LICENSE for licensing information */
 
-#define BUFFERS_PRIVATE // XXXX remove.
 #include "or.h"
 #include "buffers.h"
 #include "proto_control0.h"
@@ -14,7 +13,7 @@
 int
 peek_buf_has_control0_command(buf_t *buf)
 {
-  if (buf->datalen >= 4) {
+  if (buf_datalen(buf) >= 4) {
     char header[4];
     uint16_t cmd;
     peek_from_buf(header, sizeof(header), buf);

+ 2 - 2
src/or/proto_http.c

@@ -58,7 +58,7 @@ fetch_from_buf_http(buf_t *buf,
 
   crlf_offset = buf_find_string_offset(buf, "\r\n\r\n", 4);
   if (crlf_offset > (int)max_headerlen ||
-      (crlf_offset < 0 && buf->datalen > max_headerlen)) {
+      (crlf_offset < 0 && buf_datalen(buf) > max_headerlen)) {
     log_debug(LD_HTTP,"headers too long.");
     return -1;
   } else if (crlf_offset < 0) {
@@ -72,7 +72,7 @@ fetch_from_buf_http(buf_t *buf,
   headerlen = crlf_offset + 4;
 
   headers = buf->head->data;
-  bodylen = buf->datalen - headerlen;
+  bodylen = buf_datalen(buf) - headerlen;
   log_debug(LD_HTTP,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);
 
   if (max_headerlen <= headerlen) {

+ 7 - 7
src/or/proto_socks.c

@@ -116,7 +116,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
   ssize_t n_drain;
   size_t want_length = 128;
 
-  if (buf->datalen < 2) /* version and another byte */
+  if (buf_datalen(buf) < 2) /* version and another byte */
     return 0;
 
   do {
@@ -133,8 +133,8 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
     else if (n_drain > 0)
       buf_remove_from_front(buf, n_drain);
 
-  } while (res == 0 && buf->head && want_length < buf->datalen &&
-           buf->datalen >= 2);
+  } while (res == 0 && buf->head && want_length < buf_datalen(buf) &&
+           buf_datalen(buf) >= 2);
 
   return res;
 }
@@ -154,11 +154,11 @@ fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out)
   char hdr[EXT_OR_CMD_HEADER_SIZE];
   uint16_t len;
 
-  if (buf->datalen < EXT_OR_CMD_HEADER_SIZE)
+  if (buf_datalen(buf) < EXT_OR_CMD_HEADER_SIZE)
     return 0;
   peek_from_buf(hdr, sizeof(hdr), buf);
   len = ntohs(get_uint16(hdr+2));
-  if (buf->datalen < (unsigned)len + EXT_OR_CMD_HEADER_SIZE)
+  if (buf_datalen(buf) < (unsigned)len + EXT_OR_CMD_HEADER_SIZE)
     return 0;
   *out = ext_or_cmd_new(len);
   (*out)->cmd = ntohs(get_uint16(hdr));
@@ -526,7 +526,7 @@ parse_socks(const char *data, size_t datalen, socks_request_t *req,
           log_warn(LD_APP,"socks4: Destaddr too long. Rejecting.");
           return -1;
         }
-        // tor_assert(next < buf->cur+buf->datalen);
+        // tor_assert(next < buf->cur+buf_datalen(buf));
 
         if (log_sockstype)
           log_notice(LD_APP,
@@ -591,7 +591,7 @@ fetch_from_buf_socks_client(buf_t *buf, int state, char **reason)
 {
   ssize_t drain = 0;
   int r;
-  if (buf->datalen < 2)
+  if (buf_datalen(buf) < 2)
     return 0;
 
   buf_pullup(buf, MAX_SOCKS_MESSAGE_LEN);