aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-08-03 13:24:50 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit29b3dd1c054e8dda464c046c701d6946f53434fa (patch)
treee4a807c745e105d9d416c5f302df6cf7bf0adc4d
parent434112df4bfd4f94e553d5a41579a70765949904 (diff)
downloadtor-29b3dd1c054e8dda464c046c701d6946f53434fa.tar.gz
tor-29b3dd1c054e8dda464c046c701d6946f53434fa.zip
Fix 32-bit bug when writing address to descriptor.
We used to sizeof() a pointer. Let's just use asprintf to avoid having to be smart.
-rw-r--r--src/or/hs_service.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 6fa714e5e5..30f693108b 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -62,9 +62,9 @@
#define FOR_EACH_DESCRIPTOR_END } STMT_END ;
/* Onion service directory file names. */
-static const char *fname_keyfile_prefix = "hs_ed25519";
-static const char *fname_hostname = "hostname";
-static const char *address_tld = "onion";
+static const char fname_keyfile_prefix[] = "hs_ed25519";
+static const char fname_hostname[] = "hostname";
+static const char address_tld[] = "onion";
/* Staging list of service object. When configuring service, we add them to
* this list considered a staging area and they will get added to our global
@@ -817,20 +817,17 @@ write_address_to_file(const hs_service_t *service, const char *fname_)
{
int ret = -1;
char *fname = NULL;
- /* Length of an address plus the sizeof the address tld (onion) which counts
- * the NUL terminated byte so we keep it for the "." and the newline. */
- char buf[HS_SERVICE_ADDR_LEN_BASE32 + sizeof(address_tld) + 1];
+ char *addr_buf = NULL;
tor_assert(service);
tor_assert(fname_);
/* Construct the full address with the onion tld and write the hostname file
* to disk. */
- tor_snprintf(buf, sizeof(buf), "%s.%s\n", service->onion_address,
- address_tld);
+ tor_asprintf(&addr_buf, "%s.%s\n", service->onion_address, address_tld);
/* Notice here that we use the given "fname_". */
fname = hs_path_from_filename(service->config.directory_path, fname_);
- if (write_str_to_file(fname, buf, 0) < 0) {
+ if (write_str_to_file(fname, addr_buf, 0) < 0) {
log_warn(LD_REND, "Could not write onion address to hostname file %s",
escaped(fname));
goto end;
@@ -850,6 +847,7 @@ write_address_to_file(const hs_service_t *service, const char *fname_)
ret = 0;
end:
tor_free(fname);
+ tor_free(addr_buf);
return ret;
}