From 57359b533673961fe15184b69bcedeb219c9dd90 Mon Sep 17 00:00:00 2001 From: Karsten Loesing Date: Tue, 15 May 2012 12:39:08 +0200 Subject: [PATCH 1/4] Fix desc stats on bridge authorities that didn't serve anything. --- changes/task-5891 | 5 +++++ src/or/rephist.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 changes/task-5891 diff --git a/changes/task-5891 b/changes/task-5891 new file mode 100644 index 0000000000..79ee0029ef --- /dev/null +++ b/changes/task-5891 @@ -0,0 +1,5 @@ + o Minor bugfixes: + - Fix a bug where a bridge authority crashes if it has seen no + directory requests when it's time to write statistics to disk. + Fixes #5508 and #5891. + diff --git a/src/or/rephist.c b/src/or/rephist.c index 0cd60eeb83..173a770b18 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -2650,24 +2650,30 @@ rep_hist_format_desc_stats(time_t now) const char *key; void *val; unsigned size; - int *vals; + int *vals, max = 0, q3 = 0, md = 0, q1 = 0, min = 0; int n = 0; if (!start_of_served_descs_stats_interval) return NULL; - size = digestmap_size(served_descs); - if (size == 0) - return NULL; - vals = tor_malloc(size * sizeof(int)); - - for (iter = digestmap_iter_init(served_descs); !digestmap_iter_done(iter); - iter = digestmap_iter_next(served_descs, iter) ) { - uintptr_t count; - digestmap_iter_get(iter, &key, &val); - count = (uintptr_t)val; - vals[n++] = (int)count; - (void)key; + size = digestmap_size(served_descs); + if (size > 0) { + vals = tor_malloc(size * sizeof(int)); + for (iter = digestmap_iter_init(served_descs); + !digestmap_iter_done(iter); + iter = digestmap_iter_next(served_descs, iter)) { + uintptr_t count; + digestmap_iter_get(iter, &key, &val); + count = (uintptr_t)val; + vals[n++] = (int)count; + (void)key; + } + max = find_nth_int(vals, size, size-1); + q3 = find_nth_int(vals, size, (3*size-1)/4); + md = find_nth_int(vals, size, (size-1)/2); + q1 = find_nth_int(vals, size, (size-1)/4); + min = find_nth_int(vals, size, 0); + tor_free(vals); } format_iso_time(t, now); @@ -2678,14 +2684,8 @@ rep_hist_format_desc_stats(time_t now) t, (unsigned) (now - start_of_served_descs_stats_interval), total_descriptor_downloads, - size, - find_nth_int(vals, size, size-1), - find_nth_int(vals, size, (3*size-1)/4), - find_nth_int(vals, size, (size-1)/2), - find_nth_int(vals, size, (size-1)/4), - find_nth_int(vals, size, 0)); + size, max, q3, md, q1, min); - tor_free(vals); return result; } From e3716598fc2d06b7556d41f31d8310df19a645f5 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 15 May 2012 11:07:01 +0200 Subject: [PATCH 2/4] Assert that rep_hist_format_desc_stats() returns !NULL. The guard against this is the test for start_of_served_descs_stats_interval != 0 done earlier. --- src/or/rephist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/or/rephist.c b/src/or/rephist.c index 173a770b18..59e08e59fb 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -2705,6 +2705,7 @@ rep_hist_desc_stats_write(time_t now) return start_of_served_descs_stats_interval + WRITE_STATS_INTERVAL; str = rep_hist_format_desc_stats(now); + tor_assert(str != NULL); statsdir = get_datadir_fname("stats"); if (check_private_dir(statsdir, CPD_CREATE, get_options()->User) < 0) { From fd71fe78ae1ff6d4ddbde06d9d6f787521a6747b Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 15 May 2012 11:07:01 +0200 Subject: [PATCH 3/4] Rename changes file. --- changes/{task-5891 => bug5891} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes/{task-5891 => bug5891} (100%) diff --git a/changes/task-5891 b/changes/bug5891 similarity index 100% rename from changes/task-5891 rename to changes/bug5891 From ad61282f0c46e4b19b92e0a7ab2e2beec75acf97 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 15 May 2012 11:07:01 +0200 Subject: [PATCH 4/4] Clarify changes file regarding which bugs get fixed. --- changes/bug5891 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/bug5891 b/changes/bug5891 index 79ee0029ef..1539df3811 100644 --- a/changes/bug5891 +++ b/changes/bug5891 @@ -1,5 +1,5 @@ o Minor bugfixes: - Fix a bug where a bridge authority crashes if it has seen no directory requests when it's time to write statistics to disk. - Fixes #5508 and #5891. + Fixes bug 5891. Also fixes bug 5508 in a better way.