Skip to content

Commit 8045934

Browse files
ejohnstownphilljj
authored andcommitted
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 8a0c7a9 commit 8045934

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
@@ -504,8 +504,11 @@ static INLINE void build_addr(SOCKADDR_IN_T* addr, const char* peer,
504504
memcpy(&addr->id.is_ip_addrs, entry->h_addr_list[0],
505505
entry->h_length);
506506
#else
507-
memcpy(&addr->sin_addr.s_addr, entry->h_addr_list[0],
508-
entry->h_length);
507+
/* h_addr_list isn't always pointer aligned, copy the pointer
508+
* out rather than loading it in place */
509+
char* hostAddr;
510+
memcpy(&hostAddr, &entry->h_addr_list[0], sizeof(hostAddr));
511+
memcpy(&addr->sin_addr.s_addr, hostAddr, entry->h_length);
509512
#endif
510513
useLookup = 1;
511514
}

0 commit comments

Comments
 (0)