From: Wu, Yingcong Date: Thu, 27 Apr 2023 23:46:42 +0000 (-0700) Subject: [sanitizer] use the right type for sizeof X-Git-Tag: upstream/17.0.6~10124 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a8aab6de5de1a085e6311aa9dcfb85010acba86;p=platform%2Fupstream%2Fllvm.git [sanitizer] use the right type for sizeof `x_aliases` is an array of string, so to calculate its size, it should be times , which should be `sizeof(char*)` instead of `sizeof(char**)`. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D149242 --- diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 3bd73cf..b30c91f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7748,8 +7748,7 @@ static void write_protoent(void *ctx, struct __sanitizer_protoent *p) { for (char **pp = p->p_aliases; *pp; ++pp, ++pp_size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *pp, internal_strlen(*pp) + 1); - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_aliases, - pp_size * sizeof(char **)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, p->p_aliases, pp_size * sizeof(char *)); } INTERCEPTOR(struct __sanitizer_protoent *, getprotoent) { @@ -7855,8 +7854,7 @@ INTERCEPTOR(struct __sanitizer_netent *, getnetent) { for (char **nn = n->n_aliases; *nn; ++nn, ++nn_size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *nn, internal_strlen(*nn) + 1); - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, - nn_size * sizeof(char **)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, nn_size * sizeof(char *)); } return n; } @@ -7877,8 +7875,7 @@ INTERCEPTOR(struct __sanitizer_netent *, getnetbyname, const char *name) { for (char **nn = n->n_aliases; *nn; ++nn, ++nn_size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *nn, internal_strlen(*nn) + 1); - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, - nn_size * sizeof(char **)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, nn_size * sizeof(char *)); } return n; } @@ -7897,8 +7894,7 @@ INTERCEPTOR(struct __sanitizer_netent *, getnetbyaddr, u32 net, int type) { for (char **nn = n->n_aliases; *nn; ++nn, ++nn_size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, *nn, internal_strlen(*nn) + 1); - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, - nn_size * sizeof(char **)); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, n->n_aliases, nn_size * sizeof(char *)); } return n; } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp index 296af33..659a14c 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp @@ -23,6 +23,11 @@ void test1() { assert(ntp && ntp->n_name); assert(ntp->n_addrtype == 2); assert(ntp->n_net == 127); + char **aliases = ntp->n_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endnetent(); } @@ -31,6 +36,11 @@ void test2() { assert(ntp && ntp->n_name); assert(ntp->n_addrtype == 2); assert(ntp->n_net == 127); + char **aliases = ntp->n_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endnetent(); } @@ -41,6 +51,11 @@ void test3() { assert(ntp && ntp->n_name); assert(ntp->n_addrtype == 2); assert(ntp->n_net == 127); + char **aliases = ntp->n_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endnetent(); } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp index ff5226f..890b8bb 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp @@ -15,6 +15,11 @@ void test1() { struct protoent *ptp = getprotoent(); assert(ptp && ptp->p_name); assert(ptp->p_proto == 0); + char **aliases = ptp->p_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endprotoent(); } @@ -22,6 +27,11 @@ void test2() { struct protoent *ptp = getprotobyname("tcp"); assert(ptp && ptp->p_name); assert(ptp->p_proto == 6); + char **aliases = ptp->p_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endprotoent(); } @@ -29,6 +39,11 @@ void test3() { struct protoent *ptp = getprotobynumber(1); assert(ptp && ptp->p_name); assert(ptp->p_proto == 1); + char **aliases = ptp->p_aliases; + while (aliases) { + printf("%s\n", *aliases); + aliases++; + } endprotoent(); }