From fb18f6ef059dc2d20fa58cdcc9609bf768a11753 Mon Sep 17 00:00:00 2001 From: Andrew Scull Date: Sun, 18 Oct 2020 17:37:27 +0100 Subject: [PATCH] libmodprobe: Fail when modules.dep lacks colon The first argument in a modules.dep line must end with a colon so fail if that condition is not met. Test: libmodprobe_tests Change-Id: I6f3a22758302f16b924e5a16f7af9bf35f1a56f3 --- libmodprobe/libmodprobe.cpp | 1 + libmodprobe/libmodprobe_test.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index ceabf626c..b3ae93785 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -66,6 +66,7 @@ bool Modprobe::ParseDepCallback(const std::string& base_path, deps.emplace_back(prefix + args[0].substr(0, pos)); } else { LOG(ERROR) << "dependency lines must start with name followed by ':'"; + return false; } // Remaining items are dependencies of our module diff --git a/libmodprobe/libmodprobe_test.cpp b/libmodprobe/libmodprobe_test.cpp index 5919c49be..d50c10d8f 100644 --- a/libmodprobe/libmodprobe_test.cpp +++ b/libmodprobe/libmodprobe_test.cpp @@ -179,3 +179,16 @@ TEST(libmodprobe, Test) { m.EnableBlocklist(true); EXPECT_FALSE(m.LoadWithAliases("test4", true)); } + +TEST(libmodprobe, ModuleDepLineWithoutColonIsSkipped) { + TemporaryDir dir; + auto dir_path = std::string(dir.path); + ASSERT_TRUE(android::base::WriteStringToFile( + "no_colon.ko no_colon.ko\n", dir_path + "/modules.dep", 0600, getuid(), getgid())); + + kernel_cmdline = ""; + test_modules = {dir_path + "/no_colon.ko"}; + + Modprobe m({dir.path}); + EXPECT_FALSE(m.LoadWithAliases("no_colon", true)); +}