Commit 1e3603df authored by Nick Terrell's avatar Nick Terrell Committed by Facebook GitHub Bot

Fix 1-byte buffer overrun

Summary: Fix 1-byte buffer overrun when parsing the string "-".

Reviewed By: mhlakhani

Differential Revision: D22695995

fbshipit-source-id: 9d1834c068fc3889a514b77d53d626eb6f72b6c6
parent 6958370b
......@@ -407,7 +407,11 @@ Expected<Tgt, ConversionCode> str_to_floating(StringPiece* src) noexcept {
negative = true;
++b;
--size;
if (size == 0) {
return makeUnexpected(ConversionCode::STRING_TO_FLOAT_ERROR);
}
}
assert(size > 0);
result = 0.0;
......
......@@ -1201,6 +1201,10 @@ TEST(Conv, TryStringToFloat) {
auto rv2 = folly::tryTo<float>("3.14");
EXPECT_TRUE(rv2.hasValue());
EXPECT_NEAR(rv2.value(), 3.14, 1e-5);
// No trailing '\0' to expose 1-byte buffer over-read
char x = '-';
auto rv3 = folly::tryTo<float>(folly::StringPiece(&x, 1));
EXPECT_FALSE(rv3.hasValue());
}
TEST(Conv, TryStringToDouble) {
......
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