mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil Conway" <neil.con...@gmail.com>
Subject Re: Review Request 37903: stout: Fix bug in IPNetwork::create() with zero prefix.
Date Thu, 10 Sep 2015 05:07:12 GMT


> On Sept. 9, 2015, 11:08 p.m., Niklas Nielsen wrote:
> > 3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp, line 402
> > <https://reviews.apache.org/r/37903/diff/1/?file=1058313#file1058313line402>
> >
> >     An alternative could have been:
> >     
> >     IP(prefix == 0 ? 0 : 0xffffffff << (32 - prefix))
> >     
> >     Will let you decide what is easier to read.
> >     I like it in terms of not writing IPNetwork twice

Good suggestion -- I wasn't entirely happy with the previous syntax, either. I ended up opting
for being more explicit:

      // Avoid left-shifting by 32 bits when prefix is 0
      uint32_t mask = 0;
      if (prefix > 0) {
        mask = 0xffffffff << (32 - prefix);
      }
      return IPNetwork(address, IP(mask));


- Neil


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/37903/#review98301
-----------------------------------------------------------


On Aug. 28, 2015, 8:02 p.m., Neil Conway wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/37903/
> -----------------------------------------------------------
> 
> (Updated Aug. 28, 2015, 8:02 p.m.)
> 
> 
> Review request for mesos.
> 
> 
> Bugs: MESOS-3328
>     https://issues.apache.org/jira/browse/MESOS-3328
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> The previous coding would try to shift a uint32_t value 32 bits to the left; per
> C++ spec, this yields undefined behavior. On my machine, this resulted in
> treating a prefix of 0 as equivalent to a prefix of 32, which is obviously
> wrong.
> 
> Spotted via ubsan: see MESOS-3328.
> 
> 
> Diffs
> -----
> 
>   3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp 1ad119d54820e97497b1773518875be25ddbf98a

>   3rdparty/libprocess/3rdparty/stout/tests/ip_tests.cpp b0cbcb38cfcb923ec7c185bacf139ceb0a28924f

> 
> Diff: https://reviews.apache.org/r/37903/diff/
> 
> 
> Testing
> -------
> 
> make check
> 
> 
> Thanks,
> 
> Neil Conway
> 
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message