Opened 12 years ago

Closed 11 years ago

#5198 closed Bugs (fixed)

64 bit issue in address_v4::broadcast() with to_ulong()

Reported by: arvid@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

In address_v4.ipp:144

142 address_v4 address_v4::broadcast(const address_v4& addr, const address_v4& mask) 143 { 144 return address_v4(addr.to_ulong() | ~mask.to_ulong()); 145 }

On a 64 bit build, where long is 64 bit, inverting the mask will generate a very large number (all the upper bits will be set). Once passed into the constructor of address_v4(), this fails the bound check and throws an exception.

You might want to make to_ulong() always return uint32_t, or cast here (and in that case probably inspect all other places where to_ulong() is used).

Casting the return value from mask.to_ulong() to uint32_t before inverting it fixes this issue for me.

Change History (2)

comment:1 by arvid@…, 12 years ago

The code snipped didn't end up as I intended, here it is again:

142 address_v4 address_v4::broadcast(const address_v4& addr, const address_v4& mask)
143 {
144 return address_v4(addr.to_ulong() | ~mask.to_ulong());
145 }

comment:2 by chris_kohlhoff, 11 years ago

Resolution: fixed
Status: newclosed

Was fixed on release branch in [68200].

Note: See TracTickets for help on using tickets.