summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-07-06 14:16:12 -0700
committerElliott Hughes <enh@google.com>2015-07-06 14:37:46 -0700
commit65dd858239c4e32a5a1afbc14ac30dbcdd2a50a3 (patch)
treea90dc5897c328692b7fa6bcf48bdbc142b4d7e02
parentf643eb38c36eb63f612e20dea09fd43ac6a6b360 (diff)
downloadbionic-65dd858239c4e32a5a1afbc14ac30dbcdd2a50a3.zip
bionic-65dd858239c4e32a5a1afbc14ac30dbcdd2a50a3.tar.gz
bionic-65dd858239c4e32a5a1afbc14ac30dbcdd2a50a3.tar.bz2
Fix alignment after variable-length data.
In the serialized output from netd, the strings come first. Some code assumes -- reasonably enough -- that it can do unaligned reads of pointers, so we need to ensure alignment after all the strings. Bug: http://b/21192318 Change-Id: I456639127db9a2583f7f738e6b8103375d9387fd
-rw-r--r--libc/dns/net/gethnamaddr.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/libc/dns/net/gethnamaddr.c b/libc/dns/net/gethnamaddr.c
index 8f5800a..42f0d0a 100644
--- a/libc/dns/net/gethnamaddr.c
+++ b/libc/dns/net/gethnamaddr.c
@@ -640,6 +640,9 @@ android_read_hostent(FILE* proxy, struct hostent* hp, char* hbuf, size_t hbuflen
ptr += size;
}
+ // Fix alignment after variable-length data.
+ ptr = (char*)ALIGN(ptr);
+
int aliases_len = ((int)(aliases - aliases_ptrs) + 1) * sizeof(*hp->h_aliases);
if (ptr + aliases_len > hbuf_end) {
goto nospc;
@@ -674,6 +677,9 @@ android_read_hostent(FILE* proxy, struct hostent* hp, char* hbuf, size_t hbuflen
ptr += size;
}
+ // Fix alignment after variable-length data.
+ ptr = (char*)ALIGN(ptr);
+
int addrs_len = ((int)(addr_p - addr_ptrs) + 1) * sizeof(*hp->h_addr_list);
if (ptr + addrs_len > hbuf_end) {
goto nospc;