]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nss-myhostname: do not apply non-zero offset to null pointer 21944/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 31 Dec 2021 00:13:00 +0000 (09:13 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 31 Dec 2021 00:13:03 +0000 (09:13 +0900)
Fixes https://github.com/systemd/systemd/issues/21935#issuecomment-1003216503.

src/nss-myhostname/nss-myhostname.c

index 3536c5fc8370c5ed403f120d6f5e3a8fc16daf35..67b1554d278082aafe9ebc384ef7dbc89cdd4cd9 100644 (file)
@@ -39,10 +39,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
         const char *canonical = NULL;
         int n_addresses = 0;
         uint32_t local_address_ipv4;
-        struct local_address *a;
         size_t l, idx, ms;
         char *r_name;
-        unsigned n;
 
         PROTECT_ERRNO;
         BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
@@ -136,7 +134,9 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
         }
 
         /* Fourth, fill actual addresses in, but in backwards order */
-        for (a = addresses + n_addresses - 1, n = 0; (int) n < n_addresses; n++, a--) {
+        for (int i = n_addresses; i > 0; i--) {
+                struct local_address *a = addresses + i - 1;
+
                 r_tuple = (struct gaih_addrtuple*) (buffer + idx);
                 r_tuple->next = r_tuple_prev;
                 r_tuple->name = r_name;