Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/stdio Avoid undefined behavior in is_module_p...



details:   https://anonhg.NetBSD.org/src/rev/6f5dfcfd4c6b
branches:  trunk
changeset: 969456:6f5dfcfd4c6b
user:      kamil <kamil%NetBSD.org@localhost>
date:      Fri Feb 21 22:14:59 2020 +0000

description:
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

diffstat:

 tests/lib/libc/stdio/t_fopen.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (36 lines):

diff -r 0adc3ee837e2 -r 6f5dfcfd4c6b tests/lib/libc/stdio/t_fopen.c
--- a/tests/lib/libc/stdio/t_fopen.c    Fri Feb 21 22:04:06 2020 +0000
+++ b/tests/lib/libc/stdio/t_fopen.c    Fri Feb 21 22:14:59 2020 +0000
@@ -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 @@
        int count;
        struct iovec iov;
        modstat_t *ms;
+       modstat_t m;
 
        for (len = 8192; ;) {
                iov.iov_base = malloc(len);
@@ -336,7 +337,8 @@
        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;
                }



Home | Main Index | Thread Index | Old Index