summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorkamil <kamil@NetBSD.org>2020-02-22 00:24:15 +0000
committerkamil <kamil@NetBSD.org>2020-02-22 00:24:15 +0000
commitdc765af7de6f7050191cdedd8dc87cfb64e0aeb3 (patch)
tree15ccc6c8d6150adce364611f552d68c3b42674b2 /tests/modules
parentf46c8c6f222a21210c6018dc1df24e2cd4ba75d7 (diff)
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 (limited to 'tests/modules')
-rw-r--r--tests/modules/t_modctl.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/modules/t_modctl.c b/tests/modules/t_modctl.c
index a4fee81ebf1..fbd75de7cd1 100644
--- a/tests/modules/t_modctl.c
+++ b/tests/modules/t_modctl.c
@@ -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 @@ get_modstat_info(const char *name, modstat_t *msdest)
int count;
struct iovec iov;
modstat_t *ms;
+ modstat_t m;
check_permission();
for (len = 8192; ;) {
@@ -111,9 +112,10 @@ get_modstat_info(const char *name, modstat_t *msdest)
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;
}