From 92f339372c236d3b84188489417df2d65550b1c4 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 25 Jun 2018 12:11:53 -0700 Subject: updater: Check the number of args in Command::Parse. Additionally checks for excess args when parsing ERASE, FREE, NEW, STASH and ZERO. Note that the check for MOVE, BSDIFF, IMGDIFF has been covered in Command::ParseTargetInfoAndSourceInfo. Test: Run recovery_unit_test on marlin. Change-Id: Ic8bc9b7a8dcf98f1f8db2e259607564508726857 --- tests/unit/commands_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/unit/commands_test.cpp b/tests/unit/commands_test.cpp index bbc83b9a8..cb2be9176 100644 --- a/tests/unit/commands_test.cpp +++ b/tests/unit/commands_test.cpp @@ -310,3 +310,28 @@ TEST(CommandsTest, Parse_ZERO) { ASSERT_EQ(StashInfo(), command.stash()); ASSERT_EQ(PatchInfo(), command.patch()); } + +TEST(CommandsTest, Parse_InvalidNumberOfArgs) { + // Note that the case of having excess args in BSDIFF, IMGDIFF and MOVE is covered by + // ParseTargetInfoAndSourceInfo_InvalidInput. + std::vector inputs{ + "bsdiff", + "erase", + "erase 4,3,5,10,12 hash1", + "free", + "free id1 id2", + "imgdiff", + "move", + "new", + "new 4,3,5,10,12 hash1", + "stash", + "stash id1", + "stash id1 4,3,5,10,12 id2", + "zero", + "zero 4,3,5,10,12 hash2", + }; + for (const auto& input : inputs) { + std::string err; + ASSERT_FALSE(Command::Parse(input, 0, &err)); + } +} -- cgit v1.2.3