summaryrefslogtreecommitdiff
path: root/src/or/policies.c
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2008-08-13 19:25:18 +0000
committerPeter Palfrader <peter@palfrader.org>2008-08-13 19:25:18 +0000
commit171a7d4b0fb4341520dcf3ef512ad74eb9a86ed0 (patch)
tree2e830fe82ddbbfc5ab43a9f8831a017c71c5f3d8 /src/or/policies.c
parent864b4a009d609841043402fa1572ab13cf59e5a1 (diff)
downloadtor-171a7d4b0fb4341520dcf3ef512ad74eb9a86ed0.tar.gz
tor-171a7d4b0fb4341520dcf3ef512ad74eb9a86ed0.zip
Fix an overflow when counting rejects for *, truncate exit summaries after 1000 chars
svn:r16530
Diffstat (limited to 'src/or/policies.c')
-rw-r--r--src/or/policies.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/or/policies.c b/src/or/policies.c
index 53e7c7aacd..f8e8262ed0 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -1039,7 +1039,7 @@ policy_summary_reject(smartlist_t *summary,
{
int i = policy_summary_split(summary, prt_min, prt_max);
/* XXX: ipv4 specific */
- int count = (1 << (32-maskbits));
+ uint64_t count = (U64_LITERAL(1) << (32-maskbits));
while (i < smartlist_len(summary) &&
AT(i)->prt_max <= prt_max) {
AT(i)->reject_count += count;
@@ -1160,7 +1160,21 @@ policy_summarize(smartlist_t *policy)
accepts_str = smartlist_join_strings(accepts, ",", 0, &accepts_len);
rejects_str = smartlist_join_strings(rejects, ",", 0, &rejects_len);
- if (rejects_len < accepts_len) {
+ if (rejects_len > MAX_EXITPOLICY_SUMMARY_LEN &&
+ accepts_len > MAX_EXITPOLICY_SUMMARY_LEN) {
+ char *c;
+ shorter_str = accepts_str;
+ prefix = "accept";
+
+ c = shorter_str + (MAX_EXITPOLICY_SUMMARY_LEN-strlen(prefix)-1);
+ while (*c != ',' && c >= shorter_str)
+ c--;
+ tor_assert(c >= shorter_str);
+ tor_assert(*c == ',');
+ *c = '\0';
+
+ shorter_len = strlen(shorter_str);
+ } else if (rejects_len < accepts_len) {
shorter_str = rejects_str;
shorter_len = rejects_len;
prefix = "reject";
@@ -1171,6 +1185,7 @@ policy_summarize(smartlist_t *policy)
}
final_size = strlen(prefix)+1+shorter_len+1;
+ tor_assert(final_size <= MAX_EXITPOLICY_SUMMARY_LEN+1);
result = malloc(final_size);
tor_snprintf(result, final_size, "%s %s", prefix, shorter_str);