item_updater: Fix crash in updateUbootEnvVars()
In 25773a7 there is a change in updateUbootEnvVars() to use
versions.find(versionId)->second->path() as the flashId to update.
However, the function may be called with an invalid versionId, e.g. if
the BMC has only one activation for static layout, resetUbootEnvVars()
will not find a valid `lowestPriorityVersion`, and it will pass an empty
string to `updateUbootEnvVars()`.
Fix the issue by adding a check and return if there is no such version
found.
Tested: Verify the BMC code update for static layout with one flash is
OK.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I4bf8240fefca3ae919024a61e45cfe3d29ed01e7
diff --git a/item_updater.cpp b/item_updater.cpp
index 56c5e60..b3af305 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -658,7 +658,12 @@
void ItemUpdater::updateUbootEnvVars(const std::string& versionId)
{
- auto flashId = versions.find(versionId)->second->path();
+ auto it = versions.find(versionId);
+ if (it == versions.end())
+ {
+ return;
+ }
+ auto flashId = it->second->path();
helper.updateUbootVersionId(flashId);
}