Module Name:    src
Committed By:   kamil
Date:           Fri Feb 21 22:15:00 UTC 2020

Modified Files:
        src/tests/lib/libc/stdio: t_fopen.c

Log Message:
Avoid undefined behavior in is_module_present()

t_fopen.c:339:18, member access within misaligned address 0x7f7ff7ebd004
for type 'modstat_t' (aka 'struct modstat') which requires 8 byte alignment


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/stdio/t_fopen.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/stdio/t_fopen.c
diff -u src/tests/lib/libc/stdio/t_fopen.c:1.7 src/tests/lib/libc/stdio/t_fopen.c:1.8
--- src/tests/lib/libc/stdio/t_fopen.c:1.7	Tue Jul 16 17:29:18 2019
+++ src/tests/lib/libc/stdio/t_fopen.c	Fri Feb 21 22:14:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fopen.c,v 1.7 2019/07/16 17:29:18 martin Exp $ */
+/*	$NetBSD: t_fopen.c,v 1.8 2020/02/21 22:14:59 kamil Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fopen.c,v 1.7 2019/07/16 17:29:18 martin Exp $");
+__RCSID("$NetBSD: t_fopen.c,v 1.8 2020/02/21 22:14:59 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -314,6 +314,7 @@ is_module_present(const char *name)
 	int count;
 	struct iovec iov;
 	modstat_t *ms;
+	modstat_t m;
 
 	for (len = 8192; ;) {
 		iov.iov_base = malloc(len);
@@ -336,7 +337,8 @@ is_module_present(const char *name)
 	count = *(int *)iov.iov_base;
 	ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
 	while (count > 0) {
-		if (strcmp(ms->ms_name, name) == 0) {
+		memcpy(&m, ms, sizeof(m));
+		if (strcmp(m.ms_name, name) == 0) {
 			found = true;
 			break;
 		}

Reply via email to