};
#endif
+// This should be synchronized to ResponseCode.h
+static const int DnsProxyQueryResult = 222;
+
static const struct afd {
int a_af;
int a_addrlen;
goto exit;
}
- int remote_rv;
- if (fread(&remote_rv, sizeof(int), 1, proxy) != 1) {
+ char buf[5];
+ // read result code for gethostbyaddr
+ if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) {
goto exit;
}
- if (remote_rv != 0) {
+ int result_code = (int)strtol(buf, NULL, 10);
+ // verify the code itself
+ if (result_code != DnsProxyQueryResult ) {
goto exit;
}
socklen_t, char *, socklen_t, int));
static int hexname __P((const u_int8_t *, size_t, char *, socklen_t));
+// This should be synchronized to ResponseCode.h
+static const int DnsProxyQueryResult = 222;
+
+
/*
* Top-level getnameinfo() code. Look at the address family, and pick an
* appropriate function to call.
* the address. On failure -1 is returned in which case
* normal execution flow shall continue. */
static int
-android_gethostbyaddr_proxy(struct hostent* hp, const void *addr, socklen_t addrLen, int addrFamily) {
+android_gethostbyaddr_proxy(char* nameBuf, size_t nameBufLen, const void *addr, socklen_t addrLen, int addrFamily) {
int sock;
const int one = 1;
}
char buf[INET6_ADDRSTRLEN]; // big enough for IPv4 and IPv6
- const char* addrStr = inet_ntop(addrFamily, addr, &buf, sizeof(buf));
+ const char* addrStr = inet_ntop(addrFamily, addr, buf, sizeof(buf));
if (addrStr == NULL) {
goto exit;
}
}
result = 0;
+ char msg_buf[5];
+ // read result code for gethostbyaddr
+ if (fread(msg_buf, 1, sizeof(msg_buf), proxy) != sizeof(msg_buf)) {
+ goto exit;
+ }
+
+ int result_code = (int)strtol(msg_buf, NULL, 10);
+ // verify the code itself
+ if (result_code != DnsProxyQueryResult) {
+ goto exit;
+ }
+
uint32_t name_len;
if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) {
goto exit;
}
name_len = ntohl(name_len);
- if (name_len <= 0) {
+ if (name_len <= 0 || name_len >= nameBufLen) {
goto exit;
}
- if (fread(hp->h_name, name_len, 1, proxy) != 1) {
+ if (fread(nameBuf, name_len, 1, proxy) != 1) {
goto exit;
}
#ifdef ANDROID_CHANGES
struct hostent android_proxy_hostent;
char android_proxy_buf[MAXDNAME];
- android_proxy_hostent.h_name = android_proxy_buf;
- int hostnamelen = android_gethostbyaddr_proxy(&android_proxy_hostent,
- addr, afd->a_addrlen, afd->a_af);
- if (hostnamelen >= 0) {
- hp = (hostnamelen > 0) ? &android_proxy_hostent : NULL;
+ int hostnamelen = android_gethostbyaddr_proxy(android_proxy_buf,
+ MAXDNAME, addr, afd->a_addrlen, afd->a_af);
+ if (hostnamelen > 0) {
+ hp = &android_proxy_hostent;
+ hp->h_name = android_proxy_buf;
+ } else if (!hostnamelen) {
+ hp = NULL;
} else {
hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
}