DO NOT MERGE: Fix off-by-one error in res_cache.c

(cherry picked from commit 03844d8cdb)

Change-Id: Ib5fff46ac9211716a1577ee25bb22461c489ea9f
This commit is contained in:
Pierre Imai 2016-04-05 15:49:08 +09:00
parent 4d8e740b08
commit 8b50d08e82
4 changed files with 11 additions and 8 deletions

View 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

View 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
};

View 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++) {

View 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]);