Skip to content

Commit 3699343

Browse files
committed
tests: copy the resolver address pointer out
build_addr() copies the pointer out of entry->h_addr_list with memcpy before dereferencing it. The resolver's array is not pointer aligned on macOS, so loading the char* in place is undefined behavior and UBSan flags it on any run that reaches the gethostbyname() path.
1 parent 0986ad3 commit 3699343

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎wolfssh/test.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,11 @@ static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
492492
memcpy(&addr->id.is_ip_addrs, entry->h_addr_list[0],
493493
entry->h_length);
494494
#else
495-
memcpy(&addr->sin_addr.s_addr, entry->h_addr_list[0],
496-
entry->h_length);
495+
/* h_addr_list isn't always pointer aligned, copy the pointer
496+
* out rather than loading it in place */
497+
char* hostAddr;
498+
memcpy(&hostAddr, &entry->h_addr_list[0], sizeof(hostAddr));
499+
memcpy(&addr->sin_addr.s_addr, hostAddr, entry->h_length);
497500
#endif
498501
useLookup = 1;
499502
}

0 commit comments

Comments
 (0)