[sanitizer] use the right type for sizeof
authorWu, Yingcong <yingcong.wu@intel.com>
Thu, 27 Apr 2023 23:46:42 +0000 (16:46 -0700)
committerVitaly Buka <vitalybuka@google.com>
Thu, 27 Apr 2023 23:56:22 +0000 (16:56 -0700)
`x_aliases` is an array of string, so to calculate its size, it should
be <size-of-array> times <size-of-element>, which should be
`sizeof(char*)` instead of `sizeof(char**)`.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D149242

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp
compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp

index 3bd73cf..b30c91f 100644 (file)
@@ -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;
 }
index 296af33..659a14c 100644 (file)
@@ -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();
 }
 
index ff5226f..890b8bb 100644 (file)
@@ -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();
 }