From: James Yonan Subject: Re: [Openvpn-devel] Core dump ("unaligned access") on OpenBSD3.5 (DS10 - Alpha arch) In-Reply-To: <87wtvg1q71.fsf@...315...> Message-ID: References: <200412161458.49238.csr@...331...> <87wtvg1q71.fsf@...315...> MIME-Version: 1.0 Sender: openvpn-devel-admin@lists.sourceforge.net Errors-To: openvpn-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Id: List-Post: List-Help: List-Subscribe: , List-Archive: Date: Sat Dec 18 06:30:03 2004 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit To: Florian Weimer Cc: Christian =?iso-8859-1?Q?R=F8snes?= , openvpn-devel@lists.sourceforge.net On Sat, 18 Dec 2004, Florian Weimer wrote: > * James Yonan: > > >> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > >> Program terminated with signal 10, Bus error. > >> #0 0x120023904 in mroute_extract_addr_from_packet > >> (src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at > >> mroute.c:113 > >> 113 memcpy (src->addr, &ip->saddr, 4); > >> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > >> > >> I think my system choke on the 'ip->saddr' address in the memcpy statement. > > > > That's strange that it would hit an alignment fault on a memcpy. memcpy > > is supposed to operate at byte granularity. > > I suspect this statement is the problem: > > const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *) BPTR (buf); > > The cast results in undefined behavior if BPTR (buf) has the wrong > alignment. Recent versions of GCC know this and therefore conclude > that BPTR must be properly aligned. As a result, it is possible to > replace memcpy() with something that copies word-wise. > > The char * casts in your other message won't fix this, they come too > late. It's a common misconception that char pointers behave like > machine addresses. They don't. > > Just to be clear, this is not a bug in GCC. Your code is not valid C. That's a great observation that probably explains the alpha alignment issues -- thanks! James