Skip to content

Commit 44f877a

Browse files
committed
[compiler-rt][sanitizer-common] intercept getaddrinfo_a for Linux.
1 parent 1797fb6 commit 44f877a

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10263,6 +10263,52 @@ INTERCEPTOR(SSIZE_T, freadlink, int fd, char *buf, SIZE_T bufsiz) {
1026310263
# define INIT_FREADLINK
1026410264
#endif
1026510265

10266+
#if SANITIZER_INTERCEPT_GETADDRINFO_A
10267+
INTERCEPTOR(int, getaddrinfo_a, int mode, struct __sanitizer_gaicb *list, int num,
10268+
void* sevp) {
10269+
void *ctx;
10270+
COMMON_INTERCEPTOR_ENTER(ctx, getaddrinfo_a, mode, list, num, sevp);
10271+
if (sevp) {
10272+
COMMON_INTERCEPTOR_READ_RANGE(ctx, sevp, struct_sigevent_sz);
10273+
}
10274+
if (list) {
10275+
for (int i = 0; i < num; i ++) {
10276+
struct __sanitizer_gaicb *cb = list[i];
10277+
COMMON_INTERCEPTOR_READ_RANGE(ctx, cb, sizeof(__sanitizer_gaicb));
10278+
if (cb->ar_name)
10279+
COMMON_INTERCEPTOR_READ_RANGE(ctx, cb->ar_name, internal_strlen(cb->ar_name) + 1);
10280+
if (cb->ar_service)
10281+
COMMON_INTERCEPTOR_READ_RANGE(ctx, cb->ar_service, internal_strlen(cb->ar_service) + 1);
10282+
if (cb->ar_request) {
10283+
COMMON_INTERCEPTOR_READ_RANGE(ctx, cb->ar_request, sizeof(__sanitizer_addrinfo));
10284+
}
10285+
}
10286+
}
10287+
10288+
int res = REAL(getaddrinfo_a)(mode, list, num, sevp);
10289+
if (res == 0 && list) {
10290+
for (int i = 0; i < num; i ++) {
10291+
struct __sanitizer_addrinfo *result = list[i]->ar_result;
10292+
if (result) {
10293+
while (result) {
10294+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result, sizeof(__sanitizer_addrinfo));
10295+
if (result->ai_addr)
10296+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result->ai_addr, result->ai_addrlen);
10297+
if (result->ai_canonname)
10298+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, result->ai_canonname, internal_strlen(result->ai_canonname) + 1);
10299+
result = result->ai_next;
10300+
}
10301+
}
10302+
}
10303+
}
10304+
10305+
return res;
10306+
}
10307+
# define INIT_GETADDRINFO_A COMMON_INTERCEPT_FUNCTION(getaddrinfo_a)
10308+
#else
10309+
# define INIT_GETADDRINFO_A
10310+
#endif
10311+
1026610312
#include "sanitizer_common_interceptors_netbsd_compat.inc"
1026710313

1026810314
namespace __sanitizer {
@@ -10585,6 +10631,7 @@ static void InitializeCommonInterceptors() {
1058510631
INIT_PREADV2;
1058610632
INIT_PWRITEV2;
1058710633
INIT_FREADLINK;
10634+
INIT_GETADDRINFO_A;
1058810635

1058910636
INIT___PRINTF_CHK;
1059010637
}

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
640640
# define SI_MAC_OS_DEPLOYMENT_MIN_13_00 0
641641
#endif
642642
#define SANITIZER_INTERCEPT_FREADLINK (SI_MAC && SI_MAC_OS_DEPLOYMENT_MIN_13_00)
643+
#define SANITIZER_GETADDRINFO_A SI_LINUX
643644
// This macro gives a way for downstream users to override the above
644645
// interceptor macros irrespective of the platform they are on. They have
645646
// to do two things:

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,12 @@ CHECK_TYPE_SIZE(__kernel_old_gid_t);
11721172
CHECK_TYPE_SIZE(__kernel_off_t);
11731173
CHECK_TYPE_SIZE(__kernel_loff_t);
11741174
CHECK_TYPE_SIZE(__kernel_fd_set);
1175+
1176+
CHECK_TYPE_SIZE(gaicb);
1177+
CHECK_SIZE_AND_OFFSET(gaicb, ar_name);
1178+
CHECK_SIZE_AND_OFFSET(gaicb, ar_service);
1179+
CHECK_SIZE_AND_OFFSET(gaicb, ar_request);
1180+
CHECK_SIZE_AND_OFFSET(gaicb, ar_result);
11751181
#endif
11761182

11771183
#if !SANITIZER_ANDROID

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,16 @@ struct __sanitizer_addrinfo {
788788
struct __sanitizer_addrinfo *ai_next;
789789
};
790790

791+
#if SANITIZER_LINUX
792+
struct __sanitizer_gaicb {
793+
const char *ar_name;
794+
const char *ar_service;
795+
const struct __sanitizer_addrinfo *ar_request;
796+
struct __sanitizer_addrinfo *ar_result;
797+
int __pad[6];
798+
};
799+
#endif
800+
791801
struct __sanitizer_hostent {
792802
char *h_name;
793803
char **h_aliases;

0 commit comments

Comments
 (0)