From 6e1cd1394e5d73dfd4c4334cbf8beee79072de21 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 27 Apr 2020 04:09:42 +0300 Subject: ipa: Name IPA modules after their source directory The IPAModuleInfo::name field is currently a free-formed string that has little use. Tighten its usage rules to make it suitable for building file system paths to IPA-specific resources by matching the directory name of the IPA module. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/ipa_module.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libcamera/ipa_module.cpp') diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp index 958ede74..52823e88 100644 --- a/src/libcamera/ipa_module.cpp +++ b/src/libcamera/ipa_module.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -216,6 +217,11 @@ Span elfLoadSymbol(Span elf, const char *symbol) * \var IPAModuleInfo::name * \brief The name of the IPA module * + * The name may be used to build file system paths to IPA-specific resources. + * It shall only contain printable characters, and may not contain '/', '*', + * '?' or '\'. For IPA modules included in libcamera, it shall match the + * directory of the IPA module in the source tree. + * * \todo Allow user to choose to isolate open source IPAs */ @@ -287,6 +293,20 @@ int IPAModule::loadIPAModuleInfo() return -EINVAL; } + /* Validate the IPA module name. */ + std::string ipaName = info_.name; + auto iter = std::find_if_not(ipaName.begin(), ipaName.end(), + [](unsigned char c) -> bool { + return isprint(c) && c != '/' && + c != '?' && c != '*' && + c != '\\'; + }); + if (iter != ipaName.end()) { + LOG(IPAModule, Error) + << "Invalid IPA module name '" << ipaName << "'"; + return -EINVAL; + } + /* Load the signature. Failures are not fatal. */ File sign{ libPath_ + ".sign" }; if (!sign.open(File::ReadOnly)) { -- cgit v1.2.1