Fix use-after-free on annotation parse error
There's a mistake in 442cacfc96f69adce7b55bd28cf07a75fbcb4b65 and
55db811ed457f4e5df791a0c9e3ea545b81b687f.
It missed to set $$ when AidlAnnotation::Parse fails. When $$ is not
set, it points to the first component of the rule ($1) which is deleted.
Bug: 201125993, 201125843
Test: aidl_unittests
Change-Id: Ib5e78b3fcfb4972d31c05065ef5c946a24a8e77c
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 10268a8..57d4c6a 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -648,9 +648,14 @@
}
TEST_P(AidlTest, UnknownAnnotation) {
- const string oneway_method = "package a; @Unknown interface IFoo { }";
CaptureStderr();
- EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", oneway_method, typenames_, GetLanguage()));
+ EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", "package a; @Unknown interface IFoo { }", typenames_,
+ GetLanguage()));
+ EXPECT_THAT(GetCapturedStderr(), HasSubstr("not a recognized annotation"));
+
+ CaptureStderr();
+ EXPECT_EQ(nullptr, Parse("a/IFoo.aidl", "package a; @Unknown(param=true) interface IFoo { }",
+ typenames_, GetLanguage()));
EXPECT_THAT(GetCapturedStderr(), HasSubstr("not a recognized annotation"));
}