path: root/libc/inet
diff options
authorAlexey Brodkin <>2015-03-11 23:21:12 (GMT)
committerBernhard Reutner-Fischer <>2015-03-16 10:06:18 (GMT)
commit8ee422cffbfd3e2a16265fe6680a8dde2f5e58fe (patch)
tree6b419d566ff72881e062a4641a9ee35a7a52b44e /libc/inet
parent21cbb6fe887a30f0777521ec10f0d0d9c2a7da7e (diff)
resolv: fix unaligned tmp buffer corner-case
On execution of "inet/gethost_r-align" test I noticed failure due to unaligned access (instaed of 4-byte aligned 1-byte aligned address was attempted to be accessed). Further investigation confirmed this nice and helpful test failure. Following commit removed usage of ALIGN_BUFFER_OFFSET on entry to __read_etc_hosts_r(): So indeed if target architecture doesn't allow unaligned access and provided tmp buffer is not word aligned (and we will deal with pointers which means word-sized data units), then CPU will fail during execution. In case of ARC we'll see "Unaligned access" exception like this: --->8--- # potentially unexpected fatal signal 7. Path: /root/uClibc/test/inet/gethost_r-align CPU: 0 PID: 5514 Comm: gethost_r-align Not tainted 3.13.11 #2 task: 8f42a580 ti: 8f40e000 task.ti: 8f40e000 [ECR ]: 0x00230400 => Misaligned r/w from 0x5fdab341 [EFA ]: 0x5fdab341 [BLINK ]: 0x20032a18 [ERET ]: 0x20032a3c @off 0x12a3c in [/lib/] VMA: 0x20020000 to 0x20062000 [STAT32]: 0x00000086 : U E2 E1 BTA: 0x20046014 SP: 0x5fdab260 FP: 0x00000000 LPS: 0x20046064 LPE: 0x20046068 LPC: 0x00000000 r00: 0x5fdab341 r01: 0x00000005 r02: 0x00000015 r03: 0x00000000 r04: 0x5fdab358 r05: 0x00000000 r06: 0x0a0a0a00 r07: 0x00000000 r08: 0x0000003f r09: 0x20067050 r10: 0x00000000 r11: 0x00000014 r12: 0x00000001 r13: 0x00000000 r14: 0x20060660 r15: 0x20060661 r16: 0x00000006 r17: 0x5fdab371 r18: 0x00000018 r19: 0x5fdab2b4 r20: 0x00020000 r21: 0x00000000 r22: 0x00029068 r23: 0x5fdab371 r24: 0x00010000 r25: 0x00000000 --->8--- To fix this problem we'll re-introduce tmp buffer force alignment before config parser invocation. Signed-off-by: Alexey Brodkin <> Cc: Vineet Gupta <> Cc: Waldemar Brodkorb <> Signed-off-by: Bernhard Reutner-Fischer <>
Diffstat (limited to 'libc/inet')
1 files changed, 5 insertions, 1 deletions
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index cfc1eee..31e6381 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1615,9 +1615,13 @@ int __read_etc_hosts_r(
int ret = HOST_NOT_FOUND;
+ /* make sure pointer is aligned */
+ int i = ALIGN_BUFFER_OFFSET(buf);
+ buf += i;
+ buflen -= i;
*h_errnop = NETDB_INTERNAL;
- if (buflen < aliaslen
+ if (/* (ssize_t)buflen < 0 || */ buflen < aliaslen
|| (buflen - aliaslen) < BUFSZ + 1)
return ERANGE;
if (parser == NULL)