commit 3df37d7b6be4f7d6ece0cd12812595d5f91ea72f
parent 5edc72a45b7479f5fe791054aa19f6b3b478c725
Author: Nick Mathewson <nickm@torproject.org>
Date: Tue, 8 May 2018 14:26:05 -0400
Merge branch 'bug26004_029_squashed'
Diffstat:
3 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/changes/ticket26004 b/changes/ticket26004
@@ -0,0 +1,5 @@
+ o Minor features (directory authority, forward compatibility):
+ - Make the lines of the measured bandwidth file able to contain their
+ entries in any order. Previously, the node_id entry needed to come
+ first. Closes ticket 26004.
+
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
@@ -2459,6 +2459,18 @@ 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 */
+
+ if (strlen(line) == 0) {
+ log_warn(LD_DIRSERV, "Empty line in bandwidth file");
+ tor_free(line);
+ return -1;
+ }
+
+ /* 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
@@ -1501,6 +1501,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[] = {