From: Pierre Imai Date: Tue, 5 Apr 2016 06:49:08 +0000 (+0900) Subject: DO NOT MERGE: Fix off-by-one error in res_cache.c X-Git-Tag: android-x86-7.1-r1~80 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8b50d08;p=android-x86%2Fbionic.git DO NOT MERGE: Fix off-by-one error in res_cache.c (cherry picked from commit 03844d8cdb43c351d2c94eb67242966019f7600d) Change-Id: Ib5fff46ac9211716a1577ee25bb22461c489ea9f --- diff --git a/libc/dns/include/resolv_stats.h b/libc/dns/include/resolv_stats.h index 2aab95899..aaf6bd824 100644 --- a/libc/dns/include/resolv_stats.h +++ b/libc/dns/include/resolv_stats.h @@ -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 diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c index 526c91bc5..15f9aa43c 100644 --- a/libc/dns/resolv/res_cache.c +++ b/libc/dns/resolv/res_cache.c @@ -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 }; diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c index 95edada09..df8e131fa 100644 --- a/libc/dns/resolv/res_send.c +++ b/libc/dns/resolv/res_send.c @@ -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, ¶ms, stats); - bool usable_servers[MAXNS]; + bool usable_servers[MAXNS + 1]; _res_stats_get_usable_servers(¶ms, stats, statp->nscount, usable_servers); for (ns = 0; ns < statp->nscount; ns++) { diff --git a/libc/dns/resolv/res_stats.c b/libc/dns/resolv/res_stats.c index a3d6f36e5..b6f5ecb5e 100644 --- a/libc/dns/resolv/res_stats.c +++ b/libc/dns/resolv/res_stats.c @@ -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]);