1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

lib-addns: ensure that allocated buffer are pre set to 0

It avoid bugs when one of the buffer is supposed to contain a string
that is not null terminated (ie. label->label) and that we don't force
the last byte to 0.
This commit is contained in:
Matthieu Patou 2012-09-27 01:22:57 -07:00
parent 85259635d6
commit 03c4dceaab

View File

@ -27,7 +27,7 @@ struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx)
{ {
struct dns_buffer *result; struct dns_buffer *result;
if (!(result = talloc(mem_ctx, struct dns_buffer))) { if (!(result = talloc_zero(mem_ctx, struct dns_buffer))) {
return NULL; return NULL;
} }
@ -39,7 +39,7 @@ struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx)
*/ */
result->size = 2; result->size = 2;
if (!(result->data = talloc_array(result, uint8_t, result->size))) { if (!(result->data = talloc_zero_array(result, uint8_t, result->size))) {
TALLOC_FREE(result); TALLOC_FREE(result);
return NULL; return NULL;
} }
@ -216,14 +216,14 @@ static void dns_unmarshall_label(TALLOC_CTX *mem_ctx,
return; return;
} }
if (!(label = talloc(mem_ctx, struct dns_domain_label))) { if (!(label = talloc_zero(mem_ctx, struct dns_domain_label))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
return; return;
} }
label->len = len; label->len = len;
if (!(label->label = talloc_array(label, char, len+1))) { if (!(label->label = talloc_zero_array(label, char, len+1))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
goto error; goto error;
} }
@ -250,7 +250,7 @@ void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
if (!ERR_DNS_IS_OK(buf->error)) return; if (!ERR_DNS_IS_OK(buf->error)) return;
if (!(name = talloc(mem_ctx, struct dns_domain_name))) { if (!(name = talloc_zero(mem_ctx, struct dns_domain_name))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
return; return;
} }
@ -281,7 +281,7 @@ static void dns_unmarshall_question(TALLOC_CTX *mem_ctx,
if (!(ERR_DNS_IS_OK(buf->error))) return; if (!(ERR_DNS_IS_OK(buf->error))) return;
if (!(q = talloc(mem_ctx, struct dns_question))) { if (!(q = talloc_zero(mem_ctx, struct dns_question))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
return; return;
} }
@ -314,7 +314,7 @@ static void dns_unmarshall_rr(TALLOC_CTX *mem_ctx,
if (!(ERR_DNS_IS_OK(buf->error))) return; if (!(ERR_DNS_IS_OK(buf->error))) return;
if (!(r = talloc(mem_ctx, struct dns_rrec))) { if (!(r = talloc_zero(mem_ctx, struct dns_rrec))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
return; return;
} }
@ -329,7 +329,7 @@ static void dns_unmarshall_rr(TALLOC_CTX *mem_ctx,
if (!(ERR_DNS_IS_OK(buf->error))) return; if (!(ERR_DNS_IS_OK(buf->error))) return;
if (r->data_length != 0) { if (r->data_length != 0) {
if (!(r->data = talloc_array(r, uint8_t, r->data_length))) { if (!(r->data = talloc_zero_array(r, uint8_t, r->data_length))) {
buf->error = ERROR_DNS_NO_MEMORY; buf->error = ERROR_DNS_NO_MEMORY;
return; return;
} }
@ -406,22 +406,22 @@ DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
err = ERROR_DNS_NO_MEMORY; err = ERROR_DNS_NO_MEMORY;
if ((req->num_questions != 0) && if ((req->num_questions != 0) &&
!(req->questions = talloc_array(req, struct dns_question *, !(req->questions = talloc_zero_array(req, struct dns_question *,
req->num_questions))) { req->num_questions))) {
goto error; goto error;
} }
if ((req->num_answers != 0) && if ((req->num_answers != 0) &&
!(req->answers = talloc_array(req, struct dns_rrec *, !(req->answers = talloc_zero_array(req, struct dns_rrec *,
req->num_answers))) { req->num_answers))) {
goto error; goto error;
} }
if ((req->num_auths != 0) && if ((req->num_auths != 0) &&
!(req->auths = talloc_array(req, struct dns_rrec *, !(req->auths = talloc_zero_array(req, struct dns_rrec *,
req->num_auths))) { req->num_auths))) {
goto error; goto error;
} }
if ((req->num_additionals != 0) && if ((req->num_additionals != 0) &&
!(req->additionals = talloc_array(req, struct dns_rrec *, !(req->additionals = talloc_zero_array(req, struct dns_rrec *,
req->num_additionals))) { req->num_additionals))) {
goto error; goto error;
} }