[Bro-Dev] Alignment check in RPC code
Gregor Maier
gregor at icir.org
Fri Dec 10 18:31:45 PST 2010
Hi,
it seems that the XDR extractor, which is used by the RPC code checks
the alignment of a memory buffer before extracting data.
uint32 extract_XDR_uint32(const u_char*& buf, int& len)
{
/* ... check that buf has enough len */
uint32 bits32 = XDR_aligned(buf) ? *(uint32*) buf :
((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
buf += 4;
len -= 4;
return ntohl(bits32);
}
inline int XDR_aligned(const u_char* buf)
{
return (((unsigned long) buf) & 0x3) == 0;
}
However, on my Mac OS, buf it not 4-byte aligned. If this is the case
than the 32-bit value is byte-swapped (which is a bug, which makes the
testsuite fail on MAC OS X, which is why I discovered this code).
Mac OS X is fine with doing un-aligned reads. More general, with current
architectures and OSes, does one still need to check for 4- or 8-byte
alignments? If so, should this be done higher up in the Analyzer tree?
But my thought is that we can just remove the alignment check here.
cu
Gregor
--
Gregor Maier gregor at icir.org
Int. Computer Science Institute (ICSI) gregor at icsi.berkeley.edu
1947 Center St., Ste. 600 http://www.icir.org/gregor/
Berkeley, CA 94704
USA
More information about the bro-dev
mailing list