Theo de Raadt wrote: > > Mark Kettenis wrote: > > > CVSROOT: /cvs > > > Module name: src > > > Changes by: kette...@cvs.openbsd.org 2016/05/14 08:24:54 > > > > > > Modified files: > > > lib/libkvm : kvm.c > > > > > > Log message: > > > Revert previous commit. Converting bcopy into memcpy is never safe when > > > there is a big fat comment saying "Avoid alignment issues" immediately > > > above them. > > > > what? memcpy works on unaligned memory just fine. > > > > not when the compiler thinks "hey i can do this myself, and i am damn > sure it is aligned". > > then memcpy/memmove fail, whereas bcopy works.
ok, so the real problem here is that we're creating unaligned pointers. this is illegal C even when calling bcopy, we just get away with it. *for now.* fix that first by avoiding unsafe casts. Index: kvm.c =================================================================== RCS file: /cvs/src/lib/libkvm/kvm.c,v retrieving revision 1.61 diff -u -p -r1.61 kvm.c --- kvm.c 14 May 2016 14:24:54 -0000 1.61 +++ kvm.c 14 May 2016 16:57:07 -0000 @@ -44,6 +44,7 @@ #include <sys/exec.h> #include <sys/kcore.h> +#include <stddef.h> #include <errno.h> #include <ctype.h> #include <db.h> @@ -791,9 +792,9 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) /* * Avoid alignment issues. */ - bcopy(&((struct nlist *)rec.data)->n_type, + bcopy((char *)rec.data + offsetof(struct nlist, n_type), &p->n_type, sizeof(p->n_type)); - bcopy(&((struct nlist *)rec.data)->n_value, + bcopy((char *)rec.data + offsetof(struct nlist, n_value), &p->n_value, sizeof(p->n_value)); } /*