[tor-commits] [tor/master] Allow bandwidth-file lines to have node_id in the last position

nickm at torproject.org nickm at torproject.org
Tue May 8 18:31:52 UTC 2018


commit dbc80ad19b8a27aab557fe7930e18eef8f415133
Author: juga0 <juga at riseup.net>
Date:   Thu May 3 08:29:57 2018 +0000

    Allow bandwidth-file lines to have node_id in the last position
    
    Closes ticket 26004.
---
 src/or/dirserv.c    | 6 ++++++
 src/test/test_dir.c | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 41c6bf3dc..d9a9b8522 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2640,6 +2640,12 @@ measured_bw_line_parse(measured_bw_line_t *out, const char *orig_line)
   int got_bw = 0;
   int got_node_id = 0;
   char *strtok_state; /* lame sauce d'jour */
+
+  /* Remove end of line character, so that is not part of the token */
+  if (line[strlen(line) - 1] == '\n') {
+    line[strlen(line) - 1] = '\0';
+  }
+
   cp = tor_strtok_r(cp, " \t", &strtok_state);
 
   if (!cp) {
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index cdc56acb8..b3817a092 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -1314,6 +1314,13 @@ test_dir_measured_bw_kb(void *arg)
                 "bw=1024 junk=007\n",
     "misc=junk node_id=$557365204145532d32353620696e73746561642e  "
                 "bw=1024 junk=007\n",
+    /* check whether node_id can be at the end */
+    "bw=1024 node_id=$557365204145532d32353620696e73746561642e\n",
+    /* check whether node_id can be at the end and bw has something in front*/
+    "foo=bar bw=1024 node_id=$557365204145532d32353620696e73746561642e\n",
+    /* check whether node_id can be at the end and something in the
+     * in the middle of bw and node_id */
+    "bw=1024 foo=bar node_id=$557365204145532d32353620696e73746561642e\n",
     "end"
   };
   const char *lines_fail[] = {





More information about the tor-commits mailing list