Commit ac31e5f5 authored by Tianjiao Yin's avatar Tianjiao Yin Committed by facebook-github-bot-0

fix dangling pointer bug in IPAddressV6

Summary: `mask(numBits)` returns a temporary variable. After its lifetime ends, subbytes becomes a dangling pointer.

Reviewed By: yfeldblum

Differential Revision: D2953699

fb-gh-sync-id: 5d5a35716ecaa1b3d96edb5a459615756848b92f
shipit-source-id: 5d5a35716ecaa1b3d96edb5a459615756848b92f
parent 7bf18354
...@@ -374,8 +374,8 @@ const ByteArray16 IPAddressV6::fetchMask(size_t numBits) { ...@@ -374,8 +374,8 @@ const ByteArray16 IPAddressV6::fetchMask(size_t numBits) {
// protected // protected
bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr, bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr,
size_t numBits) const { size_t numBits) const {
const unsigned char* subbytes = mask(numBits).bytes(); auto masked = mask(numBits);
return (std::memcmp(addr.data(), subbytes, 2) == 0); return (std::memcmp(addr.data(), masked.bytes(), 2) == 0);
} }
// static private // static private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment