Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/modules Avoid undefined behavior in get_modstat_info
details: https://anonhg.NetBSD.org/src/rev/6fa93b85c6b0
branches: trunk
changeset: 745036:6fa93b85c6b0
user: kamil <kamil%NetBSD.org@localhost>
date: Sat Feb 22 00:24:15 2020 +0000
description:
Avoid undefined behavior in get_modstat_info
t_modctl.c:114:16, member access within misaligned address 0x71bf5bcede84
for type 'struct modstat_t'
t_modctl.c:116:13, load of misaligned address 0x7e81bc3c9104 for type
'struct modstat_t' which requires 8 byte alignment
diffstat:
tests/modules/t_modctl.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diffs (39 lines):
diff -r b05543dec4ad -r 6fa93b85c6b0 tests/modules/t_modctl.c
--- a/tests/modules/t_modctl.c Sat Feb 22 00:18:55 2020 +0000
+++ b/tests/modules/t_modctl.c Sat Feb 22 00:24:15 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $ */
+/* $NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $");
#include <sys/module.h>
#include <sys/sysctl.h>
@@ -87,6 +87,7 @@
int count;
struct iovec iov;
modstat_t *ms;
+ modstat_t m;
check_permission();
for (len = 8192; ;) {
@@ -111,9 +112,10 @@
count = *(int *)iov.iov_base;
ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
while ( count ) {
- if (strcmp(ms->ms_name, name) == 0) {
+ memcpy(&m, ms, sizeof(m));
+ if (strcmp(m.ms_name, name) == 0) {
if (msdest != NULL)
- *msdest = *ms;
+ memcpy(msdest, &m, sizeof(*msdest));
found = true;
break;
}
Home |
Main Index |
Thread Index |
Old Index