CID-1427760: While overrun can't happen, make it obvious that it can't
This commit is contained in:
parent
2cb68edf89
commit
62ad01d38c
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: core_elf32.c,v 1.55 2017/05/04 11:12:23 kamil Exp $ */
|
/* $NetBSD: core_elf32.c,v 1.56 2018/01/21 17:22:55 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.55 2017/05/04 11:12:23 kamil Exp $");
|
__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.56 2018/01/21 17:22:55 christos Exp $");
|
||||||
|
|
||||||
#ifdef _KERNEL_OPT
|
#ifdef _KERNEL_OPT
|
||||||
#include "opt_coredump.h"
|
#include "opt_coredump.h"
|
||||||
|
@ -505,12 +505,12 @@ save_note_bytes(struct note_state *ns, const void *data, size_t len)
|
||||||
* All but the last buffer is full.
|
* All but the last buffer is full.
|
||||||
*/
|
*/
|
||||||
for (;;) {
|
for (;;) {
|
||||||
copylen = min(len, sizeof nb->nb_data - ns->ns_offset);
|
copylen = min(len, sizeof(nb->nb_data) - ns->ns_offset);
|
||||||
wp = nb->nb_data + ns->ns_offset;
|
wp = nb->nb_data + ns->ns_offset;
|
||||||
memcpy(wp, data, copylen);
|
memcpy(wp, data, copylen);
|
||||||
if (copylen == len)
|
if (copylen == len)
|
||||||
break;
|
break;
|
||||||
nb->nb_next = kmem_alloc(sizeof *nb->nb_next, KM_SLEEP);
|
nb->nb_next = kmem_alloc(sizeof(*nb->nb_next), KM_SLEEP);
|
||||||
nb = nb->nb_next;
|
nb = nb->nb_next;
|
||||||
ns->ns_last = nb;
|
ns->ns_last = nb;
|
||||||
ns->ns_count++;
|
ns->ns_count++;
|
||||||
|
@ -519,8 +519,9 @@ save_note_bytes(struct note_state *ns, const void *data, size_t len)
|
||||||
data = (const unsigned char *)data + copylen;
|
data = (const unsigned char *)data + copylen;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (copylen & (ELFROUNDSIZE - 1))
|
while ((copylen & (ELFROUNDSIZE - 1)) &&
|
||||||
wp[copylen++] = 0;
|
wp + copylen < nb->nb_data + sizeof(nb->nb_data))
|
||||||
|
wp[copylen++] = 0;
|
||||||
|
|
||||||
ns->ns_offset += copylen;
|
ns->ns_offset += copylen;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue