Skip to content

Commit

Permalink
avoid UB in decodeAsIPv6Address()
Browse files Browse the repository at this point in the history
Order of evaluation within an expression is
undefined behavior.
  • Loading branch information
mdavidsaver committed Oct 2, 2018
1 parent 4e5aef3 commit e6902ee
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/utils/inetAddressUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ bool decodeAsIPv6Address(ByteBuffer* buffer, osiSockAddr* address) {
// allow all zeros address
//if (ffff != (int16)0xFFFF) return false;

uint32_t ipv4Addr =
((uint32_t)(buffer->getByte()&0xFF))<<24 |
((uint32_t)(buffer->getByte()&0xFF))<<16 |
((uint32_t)(buffer->getByte()&0xFF))<<8 |
((uint32_t)(buffer->getByte()&0xFF));
uint32 ipv4Addr = uint8(buffer->getByte());
ipv4Addr <<= 8;
ipv4Addr |= uint8(buffer->getByte());
ipv4Addr <<= 8;
ipv4Addr |= uint8(buffer->getByte());
ipv4Addr <<= 8;
ipv4Addr |= uint8(buffer->getByte());

if (ffff != (int16)0xFFFF && ipv4Addr != (uint32_t)0)
return false;
Expand Down

0 comments on commit e6902ee

Please sign in to comment.