xref: /aosp_15_r20/external/compiler-rt/test/msan/getaddrinfo.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_msan -O0 %s -o %t && %run %t
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot #include <sys/types.h>
4*7c3d14c8STreehugger Robot #include <sys/socket.h>
5*7c3d14c8STreehugger Robot #include <netdb.h>
6*7c3d14c8STreehugger Robot #include <stdlib.h>
7*7c3d14c8STreehugger Robot 
poison_stack_ahead()8*7c3d14c8STreehugger Robot void poison_stack_ahead() {
9*7c3d14c8STreehugger Robot   char buf[100000];
10*7c3d14c8STreehugger Robot   // With -O0 this poisons a large chunk of stack.
11*7c3d14c8STreehugger Robot }
12*7c3d14c8STreehugger Robot 
main(void)13*7c3d14c8STreehugger Robot int main(void) {
14*7c3d14c8STreehugger Robot   poison_stack_ahead();
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot   struct addrinfo *ai;
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot   // This should trigger loading of libnss_dns and friends.
19*7c3d14c8STreehugger Robot   // Those libraries are typically uninstrumented.They will call strlen() on a
20*7c3d14c8STreehugger Robot   // stack-allocated buffer, which is very likely to be poisoned. Test that we
21*7c3d14c8STreehugger Robot   // don't report this as an UMR.
22*7c3d14c8STreehugger Robot   int res = getaddrinfo("not-in-etc-hosts", NULL, NULL, &ai);
23*7c3d14c8STreehugger Robot   return 0;
24*7c3d14c8STreehugger Robot }
25