summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/test.c2
2 files changed, 5 insertions, 3 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 0b32c8fc42..cb39eb284b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -696,11 +696,12 @@ int
dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
crypto_pk_env_t *private_key)
{
- char *cp;
+ char *cp, *eos;
char digest[20];
char signature[128];
int i, written;
routerinfo_t *router;
+ eos = s+maxlen;
strncpy(s,
"signed-directory\n"
"client-software x y z\n" /* XXX make this real */
@@ -711,14 +712,13 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
cp = s+i;
for (i = 0; i < dir->n_routers; ++i) {
router = dir->routers[i];
- written = dump_router_to_string(cp, maxlen-i, router);
+ written = dump_router_to_string(cp, eos-cp, router);
if(written < 0) {
log(LOG_ERR,"dump_signed_directory_to_string(): tried to exceed string length.");
cp[maxlen-1] = 0; /* make sure it's null terminated */
return -1;
}
- i += written;
cp += written;
}
diff --git a/src/or/test.c b/src/or/test.c
index 9af2c97fcd..70f25ed0e8 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -634,6 +634,8 @@ test_dir_format()
/* puts(buf); */
test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1));
+ test_eq(2, dir2->n_routers);
+
if (pk1_str) free(pk1_str);
if (pk2_str) free(pk2_str);