Revert "netlink: Fix overallocation of netlink message buffers"

This patch was based on an incorrect assumption that the linear buffer
chain for an snl_writer only contained the netlink message body.

This reverts commit 828df4d36d.

Sponsored by:	AFRL, DARPA
This commit is contained in:
John Baldwin
2025-12-09 14:55:46 -05:00
parent cf39b51d36
commit 12165ac840
+11 -16
View File
@@ -1082,7 +1082,6 @@ snl_init_writer(struct snl_state *ss, struct snl_writer *nw)
static inline bool
snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz)
{
void *new_base;
uint32_t new_size = nw->size * 2;
while (new_size < nw->size + sz)
@@ -1091,27 +1090,23 @@ snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz)
if (nw->error)
return (false);
new_base = snl_allocz(nw->ss, new_size);
if (new_base == NULL) {
if (snl_allocz(nw->ss, new_size) == NULL) {
nw->error = true;
return (false);
}
nw->size = new_size;
if (new_base == nw->ss->lb->base) {
/* Claim the entire linear buffer. */
nw->size = nw->ss->lb->size;
nw->ss->lb->offset = nw->ss->lb->size;
} else
nw->size = new_size;
void *new_base = nw->ss->lb->base;
if (new_base != nw->base) {
memcpy(new_base, nw->base, nw->offset);
if (nw->hdr != NULL) {
int hdr_off = (char *)(nw->hdr) - nw->base;
memcpy(new_base, nw->base, nw->offset);
if (nw->hdr != NULL) {
int hdr_off = (char *)(nw->hdr) - nw->base;
nw->hdr = (struct nlmsghdr *)
(void *)((char *)new_base + hdr_off);
nw->hdr = (struct nlmsghdr *)
(void *)((char *)new_base + hdr_off);
}
nw->base = (char *)new_base;
}
nw->base = (char *)new_base;
return (true);
}