[PATCH] D119461: [compiler-rt] Fix endianness in get_sock_peer_name test

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 10 10:45:04 PST 2022


mgorny created this revision.
mgorny added reviewers: tamird, vitalybuka.
Herald added a subscriber: dberris.
mgorny requested review of this revision.

Fix passing the port and IP address with the wrong endianness
in get_sock_peer_name() that causes the connect() to fail inside
without an outgoing network interface (it's trying to connect
to 1.0.0.127 instead of 127.0.0.1).


https://reviews.llvm.org/D119461

Files:
  compiler-rt/test/sanitizer_common/TestCases/Linux/get_sock_peer_name.cpp


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/get_sock_peer_name.cpp
===================================================================
--- compiler-rt/test/sanitizer_common/TestCases/Linux/get_sock_peer_name.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/get_sock_peer_name.cpp
@@ -17,10 +17,10 @@
 
   const sockaddr_in sin = {
       .sin_family = AF_INET,
-      .sin_port = 1234,
+      .sin_port = htons(1234),
       .sin_addr =
           {
-              .s_addr = INADDR_LOOPBACK,
+              .s_addr = htonl(INADDR_LOOPBACK),
           },
   };
   assert(connect(fd, reinterpret_cast<const sockaddr *>(&sin), sizeof(sin)) ==


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119461.407603.patch
Type: text/x-patch
Size: 663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220210/19213fc2/attachment.bin>


More information about the cfe-commits mailing list