Commit 62ee9e23 authored by Simon Morlat's avatar Simon Morlat

fix potential buffer overflow while retrieving DNS servers.

parent fc22ff97
......@@ -163,6 +163,11 @@ static struct dns_resolv_conf *resconf(belle_sip_simple_resolver_context_t *ctx)
error = dns_resconf_loadfromresolv(ctx->resconf);
if (error) {
belle_sip_error("%s dns_resconf_loadfromresolv error", __FUNCTION__);
}else{
char ip[64];
char serv[10];
getnameinfo((struct sockaddr*)&ctx->resconf->nameserver[0],sizeof(struct sockaddr_in),ip,sizeof(ip),serv,sizeof(serv),NI_NUMERICHOST|NI_NUMERICSERV);
belle_sip_message("Loaded DNS server: %s",ip);
}
#else
path = "/etc/resolv.conf";
......
......@@ -4276,12 +4276,16 @@ int dns_resconf_loadfromresolv(struct dns_resolv_conf *resconf) {
if ((error = res_ninit(&res))) {
return error;
}
for (i = 0; i < res_getservers(&res,addresses,res.nscount) && i<3 /*only 3 element*/; i++ ) {
memcpy(&resconf->nameserver[i],&addresses[i],sizeof(union res_sockaddr_union));
}
error=res_getservers(&res,addresses,3);
if (error>0){
for (i = 0; i<error ; i++ ) {
memcpy(&resconf->nameserver[i],&addresses[i],sizeof(union res_sockaddr_union));
}
error=0;
}else error=-1;
res_ndestroy(&res);
return i>0?0:-1;
return error;
}
#endif /*HAVE_RESINIT*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment