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) {
// protected
bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr,
size_t numBits) const {
const unsigned char* subbytes = mask(numBits).bytes();
return (std::memcmp(addr.data(), subbytes, 2) == 0);
auto masked = mask(numBits);
return (std::memcmp(addr.data(), masked.bytes(), 2) == 0);
}
// 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