Bionic: Libc: Resolv: Stricter function signatures, unitialized return bug fix.
Stricter input parameters help avoid ugly casting when passing pointers to immutable protobuf data. While at it: an int return was dropped from 2 functions whose users never used the result; one of the return paths was returning an uninitialized value. Size_t for portablity and warning supression, misc warnings addressed. Change-Id: I2d5cbdaf0c9b6c4621a7d397772da13da5dc0943
This commit is contained in:
parent
6e1a5cf31b
commit
fbae9f3c30
@ -1834,7 +1834,7 @@ static struct in_addr* _get_addr_locked(const char * ifname);
|
|||||||
/* return 1 if the provided list of name servers differs from the list of name servers
|
/* return 1 if the provided list of name servers differs from the list of name servers
|
||||||
* currently attached to the provided cache_info */
|
* currently attached to the provided cache_info */
|
||||||
static int _resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
|
static int _resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
|
||||||
char** servers, int numservers);
|
const char** servers, int numservers);
|
||||||
/* remove a resolv_pidiface_info structure from _res_pidiface_list */
|
/* remove a resolv_pidiface_info structure from _res_pidiface_list */
|
||||||
static void _remove_pidiface_info_locked(int pid);
|
static void _remove_pidiface_info_locked(int pid);
|
||||||
/* get a resolv_pidiface_info structure from _res_pidiface_list with a certain pid */
|
/* get a resolv_pidiface_info structure from _res_pidiface_list with a certain pid */
|
||||||
@ -2077,7 +2077,7 @@ _resolv_set_default_iface(const char* ifname)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
|
_resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
|
||||||
const char *domains)
|
const char *domains)
|
||||||
{
|
{
|
||||||
int i, rt, index;
|
int i, rt, index;
|
||||||
@ -2150,7 +2150,7 @@ _resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numser
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
_resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
|
_resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
|
||||||
char** servers, int numservers)
|
const char** servers, int numservers)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char** ns;
|
char** ns;
|
||||||
@ -2272,8 +2272,8 @@ _resolv_set_addr_of_iface(const char* ifname, struct in_addr* addr)
|
|||||||
memcpy(&cache_info->ifaddr, addr, sizeof(*addr));
|
memcpy(&cache_info->ifaddr, addr, sizeof(*addr));
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
char* addr_s = inet_ntoa(cache_info->ifaddr);
|
XLOG("address of interface %s is %s\n",
|
||||||
XLOG("address of interface %s is %s\n", ifname, addr_s);
|
ifname, inet_ntoa(cache_info->ifaddr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&_res_cache_list_lock);
|
pthread_mutex_unlock(&_res_cache_list_lock);
|
||||||
@ -2412,26 +2412,24 @@ _resolv_get_pids_associated_interface(int pid, char* buff, int buffLen)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
size_t
|
||||||
_resolv_get_default_iface(char* buff, int buffLen)
|
_resolv_get_default_iface(char* buff, size_t buffLen)
|
||||||
{
|
{
|
||||||
char* ifname;
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
if (!buff || buffLen == 0) {
|
if (!buff || buffLen == 0) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_once(&_res_cache_once, _res_cache_init);
|
pthread_once(&_res_cache_once, _res_cache_init);
|
||||||
pthread_mutex_lock(&_res_cache_list_lock);
|
pthread_mutex_lock(&_res_cache_list_lock);
|
||||||
|
|
||||||
ifname = _get_default_iface_locked(); // never null, but may be empty
|
char* ifname = _get_default_iface_locked(); // never null, but may be empty
|
||||||
|
|
||||||
// if default interface not set. Get first cache with an interface
|
// if default interface not set. Get first cache with an interface
|
||||||
if (ifname[0] == '\0') {
|
if (ifname[0] == '\0') {
|
||||||
ifname = _find_any_iface_name_locked(); // may be null
|
ifname = _find_any_iface_name_locked(); // may be null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
// if we got the default iface or if (no-default) the find_any call gave an answer
|
// if we got the default iface or if (no-default) the find_any call gave an answer
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
len = strlen(ifname);
|
len = strlen(ifname);
|
||||||
@ -2448,28 +2446,32 @@ _resolv_get_default_iface(char* buff, int buffLen)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
_resolv_populate_res_for_iface(res_state statp)
|
_resolv_populate_res_for_iface(res_state statp)
|
||||||
{
|
{
|
||||||
int nserv;
|
if (statp == NULL) {
|
||||||
struct resolv_cache_info* info = NULL;
|
return;
|
||||||
|
}
|
||||||
if (statp) {
|
|
||||||
struct addrinfo* ai;
|
|
||||||
|
|
||||||
if (statp->iface[0] == '\0') { // no interface set assign default
|
if (statp->iface[0] == '\0') { // no interface set assign default
|
||||||
_resolv_get_default_iface(statp->iface, sizeof(statp->iface));
|
size_t if_len = _resolv_get_default_iface(statp->iface, sizeof(statp->iface));
|
||||||
|
if (if_len + 1 > sizeof(statp->iface)) {
|
||||||
|
XLOG("%s: INTERNAL_ERROR: can't fit interface name into statp->iface.\n", __FUNCTION__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (if_len == 0) {
|
||||||
|
XLOG("%s: INTERNAL_ERROR: can't find any suitable interfaces.\n", __FUNCTION__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_once(&_res_cache_once, _res_cache_init);
|
pthread_once(&_res_cache_once, _res_cache_init);
|
||||||
pthread_mutex_lock(&_res_cache_list_lock);
|
pthread_mutex_lock(&_res_cache_list_lock);
|
||||||
info = _find_cache_info_locked(statp->iface);
|
|
||||||
|
|
||||||
if (info == NULL) {
|
|
||||||
pthread_mutex_unlock(&_res_cache_list_lock);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
struct resolv_cache_info* info = _find_cache_info_locked(statp->iface);
|
||||||
|
if (info != NULL) {
|
||||||
|
int nserv;
|
||||||
|
struct addrinfo* ai;
|
||||||
XLOG("_resolv_populate_res_for_iface: %s\n", statp->iface);
|
XLOG("_resolv_populate_res_for_iface: %s\n", statp->iface);
|
||||||
for (nserv = 0; nserv < MAXNS; nserv++) {
|
for (nserv = 0; nserv < MAXNS; nserv++) {
|
||||||
ai = info->nsaddrinfo[nserv];
|
ai = info->nsaddrinfo[nserv];
|
||||||
@ -2503,8 +2505,6 @@ _resolv_populate_res_for_iface(res_state statp)
|
|||||||
while (pp < statp->dnsrch + MAXDNSRCH && *p != -1) {
|
while (pp < statp->dnsrch + MAXDNSRCH && *p != -1) {
|
||||||
*pp++ = &statp->defdname + *p++;
|
*pp++ = &statp->defdname + *p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&_res_cache_list_lock);
|
|
||||||
}
|
}
|
||||||
return nserv;
|
pthread_mutex_unlock(&_res_cache_list_lock);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#ifndef _RESOLV_CACHE_H_
|
#ifndef _RESOLV_CACHE_H_
|
||||||
#define _RESOLV_CACHE_H_
|
#define _RESOLV_CACHE_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
struct __res_state;
|
struct __res_state;
|
||||||
struct resolv_cache; /* forward */
|
struct resolv_cache; /* forward */
|
||||||
|
|
||||||
@ -67,14 +69,15 @@ extern struct in_addr* _resolv_get_addr_of_default_iface();
|
|||||||
/* gets the address associated with the specified interface */
|
/* gets the address associated with the specified interface */
|
||||||
extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
|
extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
|
||||||
|
|
||||||
/* Copy the name of the default interface to provided buffer.
|
/* Copy the name of the default interface to the provided buffer.
|
||||||
* Return length of buffer on success on failure -1 is returned */
|
* Returns the string length of the default interface,
|
||||||
extern int _resolv_get_default_iface(char* buff, int buffLen);
|
* be that less or more than the buffLen, or 0 if nothing had been written */
|
||||||
|
extern size_t _resolv_get_default_iface(char* buff, size_t buffLen);
|
||||||
|
|
||||||
/* sets the name server addresses to the provided res_state structure. The
|
/* sets the name server addresses to the provided res_state structure. The
|
||||||
* name servers are retrieved from the cache which is associated
|
* name servers are retrieved from the cache which is associated
|
||||||
* with the interface to which the res_state structure is associated */
|
* with the interface to which the res_state structure is associated */
|
||||||
extern int _resolv_populate_res_for_iface(struct __res_state* statp);
|
extern void _resolv_populate_res_for_iface(struct __res_state* statp);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
|
RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
|
||||||
|
@ -48,7 +48,7 @@ __BEGIN_DECLS
|
|||||||
extern void _resolv_set_default_iface(const char* ifname);
|
extern void _resolv_set_default_iface(const char* ifname);
|
||||||
|
|
||||||
/* set name servers for an interface */
|
/* set name servers for an interface */
|
||||||
extern void _resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
|
extern void _resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
|
||||||
const char *domains);
|
const char *domains);
|
||||||
|
|
||||||
/* tell resolver of the address of an interface */
|
/* tell resolver of the address of an interface */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user