aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-06-13 12:29:01 -0400
committerNick Mathewson <nickm@torproject.org>2013-06-13 12:29:01 -0400
commitcaa0d15c4902a8d376a2a79bfbfdb21bf047366a (patch)
treed6883b87bcba5019e828f34272965b879f191101 /src/or
parent25dddf7a8f30699242b52fce115f29401f63ee9c (diff)
downloadtor-caa0d15c4902a8d376a2a79bfbfdb21bf047366a.tar
tor-caa0d15c4902a8d376a2a79bfbfdb21bf047366a.tar.gz
If we write the annotation but not the microdescriptor, rewind.
This fixes bug 9047 (and some parts of 9031, 8922, 8883 that weren't fixed in 8822). Bugfix on 0.2.2.6-alpha.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/microdesc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 05e3b4181..b93bd83af 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -74,7 +74,7 @@ static ssize_t
dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
{
ssize_t r = 0;
- size_t written;
+ ssize_t written;
if (md->body == NULL) {
*annotation_len_out = 0;
return 0;
@@ -99,10 +99,10 @@ dump_microdescriptor(int fd, microdesc_t *md, size_t *annotation_len_out)
md->off = tor_fd_getpos(fd);
written = write_all(fd, md->body, md->bodylen, 0);
- if (written != md->bodylen) {
+ if (written != (ssize_t)md->bodylen) {
log_warn(LD_DIR,
- "Couldn't dump microdescriptor (wrote %lu out of %lu): %s",
- (unsigned long)written, (unsigned long)md->bodylen,
+ "Couldn't dump microdescriptor (wrote %ld out of %lu): %s",
+ (long)written, (unsigned long)md->bodylen,
strerror(errno));
return -1;
}
@@ -456,8 +456,15 @@ microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
size = dump_microdescriptor(fd, md, &annotation_len);
if (size < 0) {
- /* XXX handle errors from dump_microdescriptor() */
- /* log? return -1? die? coredump the universe? */
+ if (md->saved_location != SAVED_IN_CACHE)
+ tor_free(md->body);
+ md->saved_location = SAVED_NOWHERE;
+ md->off = 0;
+ md->bodylen = 0;
+ md->no_save = 1;
+
+ /* rewind, in case it was a partial write. */
+ tor_fd_setpos(fd, off);
continue;
}
tor_assert(((size_t)size) == annotation_len + md->bodylen);