[Dnsmasq-discuss] [PATCH] Fix alignment issue

Alex Landau landau_alex at yahoo.com
Sun Aug 5 11:37:07 BST 2007


Hi All,

I compiled dnsmasq for Blackfin (an embedded MMU-less CPU running uClinux) and
encountered the following problem: whenever dnsmasq is about to send a DNS reply it gets
a SIGBUS due to an unaligned memory access.

I traced the issue and the patch below fixes that.
The problem was in the cache_insert() function that receives (all_addr *addr) and
memcpy's it somewhere else (at the "if (addr)" statement near the end). With -O2, gcc
sees that addr is a pointer to a struct at least 4 bytes in size and replaces the memcpy
with a single 4-byte memory fetch and memory store (4-byte since I disabled IPv6).
Sometimes addr is not 4-bytes aligned (e.g. when called from extract_addresses(), the
addr parameter is casted from p1 which is a char *). In my situation this caused addr to
not be 4 bytes aligned which caused the SIGBUS.

The patch below tells gcc that the struct all_addr is packed, so gcc will not assume it
is aligned and will generate the call to memcpy instead of optimizing it.

There might be other places with the same problem. I only tested the basic DNS
functionality with no configuration file at all.

The patch is against 2.39.
Looking at 2.40rc I saw no changes in the affected code paths, but have not tested it. 

Hope to see it applied.
Regards,
Alex

--- dnsmasq.h.orig	2007-08-05 13:06:29.000000000 +0300
+++ dnsmasq.h	2007-08-05 12:58:15.000000000 +0300
@@ -125,7 +125,7 @@
     struct in6_addr addr6;
 #endif
   } addr;
-};
+} __attribute__((packed));
 
 struct bogus_addr {
   struct in_addr addr;



       
____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow  



More information about the Dnsmasq-discuss mailing list