From 8681f7e7a3953ce2627c429b2f5e8c347f28ba18 Mon Sep 17 00:00:00 2001 From: Suchang Woo Date: Tue, 6 Apr 2021 10:55:34 +0900 Subject: [PATCH] ueventd: Fix wrong argument index in devpath comparison args[2](user name to run as) is used instead of args[1](devpath). Test: atest CtsInitTestCases Signed-off-by: Suchang Woo Change-Id: Id271755993d55e332bad54d0414e2232071e5e8e --- init/ueventd_parser.cpp | 4 ++-- init/ueventd_parser_test.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp index cab988bb3..2221228d1 100644 --- a/init/ueventd_parser.cpp +++ b/init/ueventd_parser.cpp @@ -106,10 +106,10 @@ Result ParseExternalFirmwareHandlerLine( } if (std::find_if(external_firmware_handlers->begin(), external_firmware_handlers->end(), - [&args](const auto& other) { return other.devpath == args[2]; }) != + [&args](const auto& other) { return other.devpath == args[1]; }) != external_firmware_handlers->end()) { return Error() << "found a previous external_firmware_handler with the same devpath, '" - << args[2] << "'"; + << args[1] << "'"; } passwd* pwd = getpwnam(args[2].c_str()); diff --git a/init/ueventd_parser_test.cpp b/init/ueventd_parser_test.cpp index b604c53fc..4e63ba577 100644 --- a/init/ueventd_parser_test.cpp +++ b/init/ueventd_parser_test.cpp @@ -45,6 +45,13 @@ void TestSysfsPermissions(const SysfsPermissions& expected, const SysfsPermissio EXPECT_EQ(expected.attribute_, test.attribute_); } +void TestExternalFirmwareHandler(const ExternalFirmwareHandler& expected, + const ExternalFirmwareHandler& test) { + EXPECT_EQ(expected.devpath, test.devpath) << expected.devpath; + EXPECT_EQ(expected.uid, test.uid) << expected.uid; + EXPECT_EQ(expected.handler_path, test.handler_path) << expected.handler_path; +} + template void TestVector(const T& expected, const T& test, F function) { ASSERT_EQ(expected.size(), test.size()); @@ -67,6 +74,8 @@ void TestUeventdFile(const std::string& content, const UeventdConfiguration& exp TestVector(expected.sysfs_permissions, result.sysfs_permissions, TestSysfsPermissions); TestVector(expected.dev_permissions, result.dev_permissions, TestPermissions); EXPECT_EQ(expected.firmware_directories, result.firmware_directories); + TestVector(expected.external_firmware_handlers, result.external_firmware_handlers, + TestExternalFirmwareHandler); } TEST(ueventd_parser, EmptyFile) { @@ -144,7 +153,7 @@ TEST(ueventd_parser, ExternalFirmwareHandlers) { auto ueventd_file = R"( external_firmware_handler devpath root handler_path external_firmware_handler /devices/path/firmware/something001.bin system /vendor/bin/firmware_handler.sh -external_firmware_handler /devices/path/firmware/something001.bin radio "/vendor/bin/firmware_handler.sh --has --arguments" +external_firmware_handler /devices/path/firmware/something002.bin radio "/vendor/bin/firmware_handler.sh --has --arguments" )"; auto external_firmware_handlers = std::vector{ @@ -159,7 +168,7 @@ external_firmware_handler /devices/path/firmware/something001.bin radio "/vendor "/vendor/bin/firmware_handler.sh", }, { - "/devices/path/firmware/something001.bin", + "/devices/path/firmware/something002.bin", AID_RADIO, "/vendor/bin/firmware_handler.sh --has --arguments", },