aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Scull <ascull@google.com>2021-04-01 17:46:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-04-01 17:46:23 +0000
commit09e3750c145f0f4bff1c4668a3a06b9e268a9295 (patch)
tree25b8078d37783ecca96cdf6677de6322035ce15d
parent57bba0cf1892578e5eb82f3644ae0a3481156064 (diff)
parent07613905aa864d36ca4a6e863c4b7859ccbaaf0f (diff)
downloadlibcppbor-09e3750c145f0f4bff1c4668a3a06b9e268a9295.tar.gz
Error on unknown simple value am: bdc577b46b am: 07613905aa
Original change: https://android-review.googlesource.com/c/platform/external/libcppbor/+/1658065 Change-Id: Ib0c56ae07f6d6958df227d8978f7eee1aa6a6cbf
-rw-r--r--src/cppbor_parse.cpp3
-rw-r--r--tests/cppbor_test.cpp18
2 files changed, 21 insertions, 0 deletions
diff --git a/src/cppbor_parse.cpp b/src/cppbor_parse.cpp
index fcf0dac..ab01ee7 100644
--- a/src/cppbor_parse.cpp
+++ b/src/cppbor_parse.cpp
@@ -275,6 +275,9 @@ std::tuple<const uint8_t*, ParseClient*> parseRecursively(const uint8_t* begin,
return handleBool(addlData, begin, pos, parseClient);
case NULL_V:
return handleNull(begin, pos, parseClient);
+ default:
+ parseClient->error(begin, "Unsupported floating-point or simple value.");
+ return {begin, nullptr};
}
}
CHECK(false); // Impossible to get here.
diff --git a/tests/cppbor_test.cpp b/tests/cppbor_test.cpp
index ef98519..ebdcc02 100644
--- a/tests/cppbor_test.cpp
+++ b/tests/cppbor_test.cpp
@@ -1734,6 +1734,24 @@ TEST(FullParserTest, IndefiniteArray) {
message);
}
+TEST(FullParserTest, UnassignedSimpleValue) {
+ vector<uint8_t> unassignedSimpleValue = {0xE5};
+
+ auto [item, pos, message] = parse(unassignedSimpleValue);
+ EXPECT_THAT(item, IsNull());
+ EXPECT_EQ(pos, unassignedSimpleValue.data());
+ EXPECT_EQ("Unsupported floating-point or simple value.", message);
+}
+
+TEST(FullParserTest, FloatingPointValue) {
+ vector<uint8_t> floatingPointValue = {0xFA, 0x12, 0x75, 0x34, 0x37};
+
+ auto [item, pos, message] = parse(floatingPointValue);
+ EXPECT_THAT(item, IsNull());
+ EXPECT_EQ(pos, floatingPointValue.data());
+ EXPECT_EQ("Unsupported floating-point or simple value.", message);
+}
+
TEST(MapGetValueByKeyTest, Map) {
Array compoundItem(1, 2, 3, 4, 5, Map(4, 5, "a", "b"));
auto clone = compoundItem.clone();