mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
4299. [bug] Check that exactly totallen bytes are read when
reading a RRset from raw files in both single read and incremental modes. [RT #41402]
This commit is contained in:
4
CHANGES
4
CHANGES
@@ -1,3 +1,7 @@
|
|||||||
|
4299. [bug] Check that exactly totallen bytes are read when
|
||||||
|
reading a RRset from raw files in both single read
|
||||||
|
and incremental modes. [RT #41402]
|
||||||
|
|
||||||
4298. [bug] dns_rpz_add errors in loadzone were not being
|
4298. [bug] dns_rpz_add errors in loadzone were not being
|
||||||
propogated up the call stack. [RT #41425]
|
propogated up the call stack. [RT #41425]
|
||||||
|
|
||||||
|
@@ -2112,12 +2112,18 @@ pushfile(const char *master_file, dns_name_t *origin, dns_loadctx_t *lctx) {
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fill/check exists buffer with 'len' bytes. Track remaining bytes to be
|
||||||
|
* read when incrementally filling the buffer.
|
||||||
|
*/
|
||||||
static inline isc_result_t
|
static inline isc_result_t
|
||||||
read_and_check(isc_boolean_t do_read, isc_buffer_t *buffer,
|
read_and_check(isc_boolean_t do_read, isc_buffer_t *buffer,
|
||||||
size_t len, FILE *f)
|
size_t len, FILE *f, isc_uint32_t *totallen)
|
||||||
{
|
{
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
|
||||||
|
REQUIRE(totallen != NULL);
|
||||||
|
|
||||||
if (do_read) {
|
if (do_read) {
|
||||||
INSIST(isc_buffer_availablelength(buffer) >= len);
|
INSIST(isc_buffer_availablelength(buffer) >= len);
|
||||||
result = isc_stdio_read(isc_buffer_used(buffer), 1, len,
|
result = isc_stdio_read(isc_buffer_used(buffer), 1, len,
|
||||||
@@ -2125,6 +2131,9 @@ read_and_check(isc_boolean_t do_read, isc_buffer_t *buffer,
|
|||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
return (result);
|
return (result);
|
||||||
isc_buffer_add(buffer, (unsigned int)len);
|
isc_buffer_add(buffer, (unsigned int)len);
|
||||||
|
if (*totallen < len)
|
||||||
|
return (ISC_R_RANGE);
|
||||||
|
*totallen -= len;
|
||||||
} else if (isc_buffer_remaininglength(buffer) < len)
|
} else if (isc_buffer_remaininglength(buffer) < len)
|
||||||
return (ISC_R_RANGE);
|
return (ISC_R_RANGE);
|
||||||
|
|
||||||
@@ -2340,6 +2349,7 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
isc_buffer_add(&target, sizeof(totallen));
|
isc_buffer_add(&target, sizeof(totallen));
|
||||||
totallen = isc_buffer_getuint32(&target);
|
totallen = isc_buffer_getuint32(&target);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validation: the input data must at least contain the common
|
* Validation: the input data must at least contain the common
|
||||||
* header.
|
* header.
|
||||||
@@ -2381,6 +2391,7 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
isc_buffer_add(&target, (unsigned int)readlen);
|
isc_buffer_add(&target, (unsigned int)readlen);
|
||||||
|
totallen -= readlen;
|
||||||
|
|
||||||
/* Construct RRset headers */
|
/* Construct RRset headers */
|
||||||
dns_rdatalist_init(&rdatalist);
|
dns_rdatalist_init(&rdatalist);
|
||||||
@@ -2401,7 +2412,7 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
|
|
||||||
/* Owner name: length followed by name */
|
/* Owner name: length followed by name */
|
||||||
result = read_and_check(sequential_read, &target,
|
result = read_and_check(sequential_read, &target,
|
||||||
sizeof(namelen), lctx->f);
|
sizeof(namelen), lctx->f, &totallen);
|
||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
namelen = isc_buffer_getuint16(&target);
|
namelen = isc_buffer_getuint16(&target);
|
||||||
@@ -2411,7 +2422,7 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = read_and_check(sequential_read, &target, namelen,
|
result = read_and_check(sequential_read, &target, namelen,
|
||||||
lctx->f);
|
lctx->f, &totallen);
|
||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@@ -2481,14 +2492,15 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
|
|
||||||
/* rdata length */
|
/* rdata length */
|
||||||
result = read_and_check(sequential_read, &target,
|
result = read_and_check(sequential_read, &target,
|
||||||
sizeof(rdlen), lctx->f);
|
sizeof(rdlen), lctx->f,
|
||||||
|
&totallen);
|
||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
rdlen = isc_buffer_getuint16(&target);
|
rdlen = isc_buffer_getuint16(&target);
|
||||||
|
|
||||||
/* rdata */
|
/* rdata */
|
||||||
result = read_and_check(sequential_read, &target,
|
result = read_and_check(sequential_read, &target,
|
||||||
rdlen, lctx->f);
|
rdlen, lctx->f, &totallen);
|
||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
isc_buffer_setactive(&target, (unsigned int)rdlen);
|
isc_buffer_setactive(&target, (unsigned int)rdlen);
|
||||||
@@ -2514,7 +2526,7 @@ load_raw(dns_loadctx_t *lctx) {
|
|||||||
* necessarily critical, but it very likely indicates broken
|
* necessarily critical, but it very likely indicates broken
|
||||||
* or malformed data.
|
* or malformed data.
|
||||||
*/
|
*/
|
||||||
if (isc_buffer_remaininglength(&target) != 0) {
|
if (isc_buffer_remaininglength(&target) != 0 || totallen != 0) {
|
||||||
result = ISC_R_RANGE;
|
result = ISC_R_RANGE;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user