[or-cvs] r13385: Fix a potential bug that would make authorities fail to vote (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Feb 5 21:39:36 UTC 2008


Author: nickm
Date: 2008-02-05 16:39:36 -0500 (Tue, 05 Feb 2008)
New Revision: 13385

Modified:
   tor/trunk/
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/dirvote.c
   tor/trunk/src/or/or.h
Log:
 r17911 at catbus:  nickm | 2008-02-05 15:53:22 -0500
 Fix a potential bug that would make authorities fail to vote under bizarre circumstances that probably never happened.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r17911] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2008-02-05 21:39:32 UTC (rev 13384)
+++ tor/trunk/src/or/dirserv.c	2008-02-05 21:39:36 UTC (rev 13385)
@@ -1868,6 +1868,7 @@
   if (first_line_only)
     return 0;
   cp = buf + strlen(buf);
+  /* NOTE: Whenever this list expands, be sure to increase MAX_FLAG_LINE_LEN*/
   r = tor_snprintf(cp, buf_len - (cp-buf),
                    "s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
                   /* These must stay in alphabetical order. */
@@ -1890,7 +1891,9 @@
   }
   cp += strlen(cp);
 
-  if (version) {
+  /* length of "opt v \n" */
+#define V_LINE_OVERHEAD 7
+  if (version && strlen(version) < MAX_V_LINE_LEN - V_LINE_OVERHEAD) {
     if (tor_snprintf(cp, buf_len - (cp-buf), "opt v %s\n", version)<0) {
       log_warn(LD_BUG, "Unable to print router version.");
       return -1;
@@ -2280,17 +2283,15 @@
 static cached_dir_t *
 generate_v2_networkstatus_opinion(void)
 {
-/** Longest status flag name that we generate. */
-#define LONGEST_STATUS_FLAG_NAME_LEN 9
-/** Maximum number of status flags we'll apply to one router. */
-#define N_STATUS_FLAGS 10
 /** Amount of space to allocate for each entry. (r line and s line.) */
 #define RS_ENTRY_LEN                                                    \
   ( /* first line */                                                    \
    MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
    5*2 /* ports */ + 10 /* punctuation */ +                             \
    /* second line */                                                    \
-   (LONGEST_STATUS_FLAG_NAME_LEN+1)*N_STATUS_FLAGS + 2)
+   (MAX_FLAG_LINE_LEN) +                                                \
+   /* third line */                                                     \
+   (MAX_V_LINE_LEN))
 
   cached_dir_t *r = NULL;
   size_t len, identity_pkey_len;

Modified: tor/trunk/src/or/dirvote.c
===================================================================
--- tor/trunk/src/or/dirvote.c	2008-02-05 21:39:32 UTC (rev 13384)
+++ tor/trunk/src/or/dirvote.c	2008-02-05 21:39:36 UTC (rev 13385)
@@ -36,19 +36,15 @@
 format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
                           networkstatus_t *v3_ns)
 {
-/** Longest status flag name that we generate. */
-#define LONGEST_STATUS_FLAG_NAME_LEN 9
-/** Maximum number of status flags we'll apply to one router. */
-#define N_STATUS_FLAGS 10
 /** Amount of space to allocate for each entry: r, s, and v lines. */
 #define RS_ENTRY_LEN                                                    \
   ( /* first line */                                                    \
    MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
    5*2 /* ports */ + 10 /* punctuation */ +                             \
    /* second line */                                                    \
-   (LONGEST_STATUS_FLAG_NAME_LEN+1)*N_STATUS_FLAGS + 2 +                \
-   /* v line.  XXXX020 not accurate! */                                 \
-   80                                                                   \
+   MAX_FLAG_LINE_LEN +                                                  \
+   /* v line. */                                                        \
+   MAX_V_LINE_LEN                                                       \
    )
 
   size_t len;

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-02-05 21:39:32 UTC (rev 13384)
+++ tor/trunk/src/or/or.h	2008-02-05 21:39:36 UTC (rev 13385)
@@ -3049,7 +3049,11 @@
 }
 
 /********************************* dirserv.c ***************************/
-
+/** Maximum allowable length of a version line in a networkstatus. */
+#define MAX_V_LINE_LEN 128
+/** Length of "r Authority BadDirectory BadExit Exit Fast Guard HSDir Named
+ * Running Stable Unnamed V2Dir Valid\n". */
+#define MAX_FLAG_LINE_LEN 96
 #define UNNAMED_ROUTER_NICKNAME "Unnamed"
 
 int connection_dirserv_flushed_some(dir_connection_t *conn);



More information about the tor-commits mailing list