malloc checks
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4117 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -111,6 +111,8 @@ parse_reply(unsigned char *data, int len)
|
|||||||
struct resource_record **rr;
|
struct resource_record **rr;
|
||||||
|
|
||||||
r = (struct dns_reply*)malloc(sizeof(struct dns_reply));
|
r = (struct dns_reply*)malloc(sizeof(struct dns_reply));
|
||||||
|
if (r == NULL)
|
||||||
|
return NULL;
|
||||||
memset(r, 0, sizeof(struct dns_reply));
|
memset(r, 0, sizeof(struct dns_reply));
|
||||||
|
|
||||||
p = data;
|
p = data;
|
||||||
@@ -122,6 +124,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
r->q.domain = strdup(host);
|
r->q.domain = strdup(host);
|
||||||
|
if(r->q.domain == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
p += status;
|
p += status;
|
||||||
r->q.type = (p[0] << 8 | p[1]);
|
r->q.type = (p[0] << 8 | p[1]);
|
||||||
p += 2;
|
p += 2;
|
||||||
@@ -146,7 +152,15 @@ parse_reply(unsigned char *data, int len)
|
|||||||
p += 2;
|
p += 2;
|
||||||
*rr = (struct resource_record*)calloc(1,
|
*rr = (struct resource_record*)calloc(1,
|
||||||
sizeof(struct resource_record));
|
sizeof(struct resource_record));
|
||||||
|
if(*rr == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
(*rr)->domain = strdup(host);
|
(*rr)->domain = strdup(host);
|
||||||
|
if((*rr)->domain == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
(*rr)->type = type;
|
(*rr)->type = type;
|
||||||
(*rr)->class = class;
|
(*rr)->class = class;
|
||||||
(*rr)->ttl = ttl;
|
(*rr)->ttl = ttl;
|
||||||
@@ -161,6 +175,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
(*rr)->u.txt = strdup(host);
|
(*rr)->u.txt = strdup(host);
|
||||||
|
if((*rr)->u.txt == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case T_MX:
|
case T_MX:
|
||||||
case T_AFSDB:{
|
case T_AFSDB:{
|
||||||
@@ -171,6 +189,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
}
|
}
|
||||||
(*rr)->u.mx = (struct mx_record*)malloc(sizeof(struct mx_record) +
|
(*rr)->u.mx = (struct mx_record*)malloc(sizeof(struct mx_record) +
|
||||||
strlen(host));
|
strlen(host));
|
||||||
|
if((*rr)->u.mx == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
(*rr)->u.mx->preference = (p[0] << 8) | p[1];
|
(*rr)->u.mx->preference = (p[0] << 8) | p[1];
|
||||||
strcpy((*rr)->u.mx->domain, host);
|
strcpy((*rr)->u.mx->domain, host);
|
||||||
break;
|
break;
|
||||||
@@ -184,6 +206,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
(*rr)->u.srv =
|
(*rr)->u.srv =
|
||||||
(struct srv_record*)malloc(sizeof(struct srv_record) +
|
(struct srv_record*)malloc(sizeof(struct srv_record) +
|
||||||
strlen(host));
|
strlen(host));
|
||||||
|
if((*rr)->u.srv == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
(*rr)->u.srv->priority = (p[0] << 8) | p[1];
|
(*rr)->u.srv->priority = (p[0] << 8) | p[1];
|
||||||
(*rr)->u.srv->weight = (p[2] << 8) | p[3];
|
(*rr)->u.srv->weight = (p[2] << 8) | p[3];
|
||||||
(*rr)->u.srv->port = (p[4] << 8) | p[5];
|
(*rr)->u.srv->port = (p[4] << 8) | p[5];
|
||||||
@@ -192,6 +218,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
}
|
}
|
||||||
case T_TXT:{
|
case T_TXT:{
|
||||||
(*rr)->u.txt = (char*)malloc(size + 1);
|
(*rr)->u.txt = (char*)malloc(size + 1);
|
||||||
|
if((*rr)->u.txt == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
strncpy((*rr)->u.txt, (char*)p + 1, *p);
|
strncpy((*rr)->u.txt, (char*)p + 1, *p);
|
||||||
(*rr)->u.txt[*p] = 0;
|
(*rr)->u.txt[*p] = 0;
|
||||||
break;
|
break;
|
||||||
@@ -199,6 +229,10 @@ parse_reply(unsigned char *data, int len)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
(*rr)->u.data = (unsigned char*)malloc(size);
|
(*rr)->u.data = (unsigned char*)malloc(size);
|
||||||
|
if((*rr)->u.data == NULL) {
|
||||||
|
dns_free_data(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy((*rr)->u.data, p, size);
|
memcpy((*rr)->u.data, p, size);
|
||||||
}
|
}
|
||||||
p += size;
|
p += size;
|
||||||
@@ -215,7 +249,7 @@ dns_lookup(const char *domain, const char *type_name)
|
|||||||
int len;
|
int len;
|
||||||
int type;
|
int type;
|
||||||
struct dns_reply *r = NULL;
|
struct dns_reply *r = NULL;
|
||||||
u_long old_options;
|
u_long old_options = 0;
|
||||||
|
|
||||||
type = string_to_type(type_name);
|
type = string_to_type(type_name);
|
||||||
if (krb_dns_debug) {
|
if (krb_dns_debug) {
|
||||||
|
Reference in New Issue
Block a user