Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern CID-1427760: While overrun can't happen, make it ob...
details: https://anonhg.NetBSD.org/src/rev/5df467850473
branches: trunk
changeset: 358895:5df467850473
user: christos <christos%NetBSD.org@localhost>
date: Sun Jan 21 17:22:55 2018 +0000
description:
CID-1427760: While overrun can't happen, make it obvious that it can't
diffstat:
sys/kern/core_elf32.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diffs (45 lines):
diff -r a72641653afa -r 5df467850473 sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c Sun Jan 21 16:55:25 2018 +0000
+++ b/sys/kern/core_elf32.c Sun Jan 21 17:22:55 2018 +0000
@@ -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.
@@ -40,7 +40,7 @@
*/
#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
#include "opt_coredump.h"
@@ -505,12 +505,12 @@
* All but the last buffer is full.
*/
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;
memcpy(wp, data, copylen);
if (copylen == len)
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;
ns->ns_last = nb;
ns->ns_count++;
@@ -519,8 +519,9 @@
data = (const unsigned char *)data + copylen;
}
- while (copylen & (ELFROUNDSIZE - 1))
- wp[copylen++] = 0;
+ while ((copylen & (ELFROUNDSIZE - 1)) &&
+ wp + copylen < nb->nb_data + sizeof(nb->nb_data))
+ wp[copylen++] = 0;
ns->ns_offset += copylen;
}
Home |
Main Index |
Thread Index |
Old Index