--- embedaddon/dnsmasq/src/blockdata.c 2014/06/15 16:31:38 1.1.1.1 +++ embedaddon/dnsmasq/src/blockdata.c 2023/09/27 11:02:07 1.1.1.4 @@ -1,4 +1,4 @@ -/* dnsmasq is Copyright (c) 2000-2014 Simon Kelley +/* dnsmasq is Copyright (c) 2000-2022 Simon Kelley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,8 +16,6 @@ #include "dnsmasq.h" -#ifdef HAVE_DNSSEC - static struct blockdata *keyblock_free; static unsigned int blockdata_count, blockdata_hwm, blockdata_alloced; @@ -25,7 +23,7 @@ static void blockdata_expand(int n) { struct blockdata *new = whine_malloc(n * sizeof(struct blockdata)); - if (n > 0 && new) + if (new) { int i; @@ -49,19 +47,18 @@ void blockdata_init(void) /* Note that daemon->cachesize is enforced to have non-zero size if OPT_DNSSEC_VALID is set */ if (option_bool(OPT_DNSSEC_VALID)) - blockdata_expand((daemon->cachesize * 100) / sizeof(struct blockdata)); + blockdata_expand(daemon->cachesize); } void blockdata_report(void) { - if (option_bool(OPT_DNSSEC_VALID)) - my_syslog(LOG_INFO, _("DNSSEC memory in use %u, max %u, allocated %u"), - blockdata_count * sizeof(struct blockdata), - blockdata_hwm * sizeof(struct blockdata), - blockdata_alloced * sizeof(struct blockdata)); + my_syslog(LOG_INFO, _("pool memory in use %zu, max %zu, allocated %zu"), + blockdata_count * sizeof(struct blockdata), + blockdata_hwm * sizeof(struct blockdata), + blockdata_alloced * sizeof(struct blockdata)); } -struct blockdata *blockdata_alloc(char *data, size_t len) +static struct blockdata *blockdata_alloc_real(int fd, char *data, size_t len) { struct blockdata *block, *ret = NULL; struct blockdata **prev = &ret; @@ -89,8 +86,17 @@ struct blockdata *blockdata_alloc(char *data, size_t l blockdata_hwm = blockdata_count; blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len; - memcpy(block->key, data, blen); - data += blen; + if (data) + { + memcpy(block->key, data, blen); + data += blen; + } + else if (!read_write(fd, block->key, blen, 1)) + { + /* failed read free partial chain */ + blockdata_free(ret); + return NULL; + } len -= blen; *prev = block; prev = &block->next; @@ -100,6 +106,11 @@ struct blockdata *blockdata_alloc(char *data, size_t l return ret; } +struct blockdata *blockdata_alloc(char *data, size_t len) +{ + return blockdata_alloc_real(0, data, len); +} + void blockdata_free(struct blockdata *blocks) { struct blockdata *tmp; @@ -147,5 +158,19 @@ void *blockdata_retrieve(struct blockdata *block, size return data; } - -#endif + + +void blockdata_write(struct blockdata *block, size_t len, int fd) +{ + for (; len > 0 && block; block = block->next) + { + size_t blen = len > KEYBLOCK_LEN ? KEYBLOCK_LEN : len; + read_write(fd, block->key, blen, 0); + len -= blen; + } +} + +struct blockdata *blockdata_read(int fd, size_t len) +{ + return blockdata_alloc_real(fd, NULL, len); +}