]> granicus.if.org Git - file/commitdiff
Avoid OOB read (found by ASAN reported by F. Alonso)
authorChristos Zoulas <christos@zoulas.com>
Wed, 2 Jan 2019 19:44:14 +0000 (19:44 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 2 Jan 2019 19:44:14 +0000 (19:44 +0000)
src/readelf.c

index 4f4103a1d1aa57659999bbe21b7f1c31b0bfc473..8d57896645b191d4884c3354ce94c6e08f1dc9a2 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.156 2018/10/19 00:33:04 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.157 2019/01/02 19:44:14 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -752,7 +752,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
                        char sbuf[512];
                        struct NetBSD_elfcore_procinfo pi;
                        memset(&pi, 0, sizeof(pi));
-                       memcpy(&pi, nbuf + doff, descsz);
+                       memcpy(&pi, nbuf + doff, MIN(descsz, sizeof(pi)));
 
                        if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
                            "gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",