> From: "Ted Unangst" <t...@tedunangst.com> > Date: Sat, 14 May 2016 12:59:20 -0400 > > 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.
Well, I think that makes the code less readable. Just leave it as is. It's not as if bcopy(3) will ever go away. > 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)); > } > /*