OSDN Git Service

DO NOT MERGE: Fix off-by-one error in res_cache.c
authorPierre Imai <imaipi@google.com>
Tue, 5 Apr 2016 06:49:08 +0000 (15:49 +0900)
committerPierre Imai <imaipi@google.com>
Wed, 6 Apr 2016 01:44:00 +0000 (10:44 +0900)
(cherry picked from commit 03844d8cdb43c351d2c94eb67242966019f7600d)

Change-Id: Ib5fff46ac9211716a1577ee25bb22461c489ea9f

libc/dns/include/resolv_stats.h
libc/dns/resolv/res_cache.c
libc/dns/resolv/res_send.c
libc/dns/resolv/res_stats.c

index 2aab958..aaf6bd8 100644 (file)
@@ -67,7 +67,7 @@ _res_stats_usable_server(const struct __res_params* params, struct __res_stats*
 
 /* Returns an array of bools indicating which servers are considered good */
 extern void
-_res_stats_get_usable_servers(const struct __res_params* params, struct __res_stats stats[MAXNS],
-        int nscount, bool valid_servers[MAXNS]);
+_res_stats_get_usable_servers(const struct __res_params* params, struct __res_stats stats[],
+        int nscount, bool valid_servers[]);
 
 #endif  // _RES_STATS_H
index 526c91b..15f9aa4 100644 (file)
@@ -1228,15 +1228,18 @@ typedef struct resolv_cache {
     PendingReqInfo   pending_requests;
 } Cache;
 
+// The nameservers[], nsaddrinfo[] and nsstats[] are containing MAXNS + 1 elements, because the
+// number of nameservers is not known and the code relies on the n+1-st entry to be null to
+// recognize the end.
 struct resolv_cache_info {
     unsigned                    netid;
     Cache*                      cache;
     struct resolv_cache_info*   next;
-    char*                       nameservers[MAXNS +1];
+    char*                       nameservers[MAXNS + 1];
     struct addrinfo*            nsaddrinfo[MAXNS + 1];
     int                         revision_id; // # times the nameservers have been replaced
     struct __res_params         params;
-    struct __res_stats          nsstats[MAXNS];
+    struct __res_stats          nsstats[MAXNS + 1];
     char                        defdname[256];
     int                         dnsrch_offset[MAXDNSRCH+1];  // offsets into defdname
 };
index 95edada..df8e131 100644 (file)
@@ -488,10 +488,10 @@ res_nsend(res_state statp,
         * Send request, RETRY times, or until successful.
         */
        for (try = 0; try < statp->retry; try++) {
-           struct __res_stats stats[MAXNS];
+           struct __res_stats stats[MAXNS + 1];
            struct __res_params params;
            int revision_id = _resolv_cache_get_resolver_stats(statp->netid, &params, stats);
-           bool usable_servers[MAXNS];
+           bool usable_servers[MAXNS + 1];
            _res_stats_get_usable_servers(&params, stats, statp->nscount, usable_servers);
 
            for (ns = 0; ns < statp->nscount; ns++) {
index a3d6f36..b6f5ecb 100644 (file)
@@ -164,8 +164,8 @@ _res_stats_usable_server(const struct __res_params* params, struct __res_stats*
 }
 
 void
-_res_stats_get_usable_servers(const struct __res_params* params, struct __res_stats stats[MAXNS],
-        int nscount, bool usable_servers[MAXNS]) {
+_res_stats_get_usable_servers(const struct __res_params* params, struct __res_stats stats[],
+        int nscount, bool usable_servers[]) {
     unsigned usable_servers_found = 0;
     for (int ns = 0; ns < nscount; ns++) {
         bool usable = _res_stats_usable_server(params, &stats[ns]);