Skip to content
Snippets Groups Projects
Commit d07c4610 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Fixed memory invalid read

The reason was the rdata_base32_to_string must return string terminated with 0.
New implementation of Base32hex doesn't do that. So additional termination was
added.

refs #2137 @2h
parent 04fd98a1
No related branches found
No related tags found
No related merge requests found
......@@ -549,25 +549,33 @@ static char *rdata_time_to_string(knot_rdata_item_t item)
static char *rdata_base32_to_string(knot_rdata_item_t item)
{
int32_t length;
char *ret = NULL;
size_t size = rdata_item_size(item);
if (size == 0) {
char *ret = malloc(sizeof(char) * 2);
ret = malloc(2);
ret[0] = '-';
ret[1] = '\0';
return ret;
}
size -= 1; // remove length byte from count
char *ret = NULL;
length = base32hex_encode_alloc(rdata_item_data(item) + 1,
size, (uint8_t **)(&ret));
if (length > 0) {
return ret;
} else {
free(ret);
return NULL;
int32_t b32_out;
uint32_t out_len = ((size + 4) / 5) * 8;
ret = malloc(out_len + 1);
b32_out = base32hex_encode(rdata_item_data(item) + 1,
size - 1,
(uint8_t *)ret,
out_len);
if (b32_out <= 0) {
free(ret);
ret = NULL;
}
ret[b32_out] = '\0';
}
return ret;
}
/*!< \todo Replace with function from .../common after release. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment