]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Allow bandwidth-file lines to have node_id in the last position
authorjuga0 <juga@riseup.net>
Thu, 3 May 2018 08:29:57 +0000 (08:29 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 8 May 2018 18:24:29 +0000 (14:24 -0400)
Closes ticket 26004.

src/or/dirserv.c
src/test/test_dir.c

index 41c6bf3dc8d063d370986922fc36b262e27a3f3e..d9a9b8522db392364e17f2f4665b64d650383646 100644 (file)
@@ -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) {
index cdc56acb899d73606bdda1c6c557788189855f3f..b3817a09299102b81204a20630ffebe116d1c7e6 100644 (file)
@@ -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[] = {