Module Name:    src
Committed By:   mgorny
Date:           Wed Jan  8 17:22:40 UTC 2020

Modified Files:
        src/tests/lib/libc/sys: t_ptrace_wait.c

Log Message:
Fix alignment when reading core notes

Both desc and note header needs to be aligned.  Therefore, we need
to realign after skipping past desc as well.

While at it, fix the other alignment fix to use roundup() macro.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/tests/lib/libc/sys/t_ptrace_wait.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/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.145 src/tests/lib/libc/sys/t_ptrace_wait.c:1.146
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.145	Wed Dec 25 02:23:37 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Wed Jan  8 17:22:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $	*/
+/*	$NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $	*/
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.145 2019/12/25 02:23:37 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $");
 
 #define __LEGACY_PT_LWPINFO
 
@@ -7837,8 +7837,7 @@ static ssize_t core_find_note(const char
 
 			offset += note_hdr.n_namesz;
 			/* fix to alignment */
-			offset = ((offset + core_hdr.p_align - 1)
-			    / core_hdr.p_align) * core_hdr.p_align;
+			offset = roundup(offset, core_hdr.p_align);
 
 			/* if name & type matched above */
 			if (ret != -1) {
@@ -7850,6 +7849,8 @@ static ssize_t core_find_note(const char
 			}
 
 			offset += note_hdr.n_descsz;
+			/* fix to alignment */
+			offset = roundup(offset, core_hdr.p_align);
 		}
 	}
 

Reply via email to