From 1dfb086ca8220bee3ad978ac64df0c988853aa44 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Tue, 16 Feb 2021 20:03:54 +0100 Subject: updater: Do not null terminate mount_flags_list array mount_flags_list is a c-style NULL terminated array, but when iterating over it via for (const auto& [name, value] : mount_flags_list) the last { 0, 0 } is considered a valid entry. Then `name` is NULL but checked with (flag == name), which causes SIGSEGV. Also move the definition to within setMountFlag() and make it an std::pair array Change-Id: Ia6670113620c6e8f95151fda764c3ab40bc2d67e --- updater/updater_runtime.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/updater/updater_runtime.cpp b/updater/updater_runtime.cpp index e93830505..bac078cf9 100644 --- a/updater/updater_runtime.cpp +++ b/updater/updater_runtime.cpp @@ -44,29 +44,25 @@ std::string UpdaterRuntime::FindBlockDeviceName(const std::string_view name) con return std::string(name); } -static struct { - const char* name; - unsigned flag; -} mount_flags_list[] = { - { "noatime", MS_NOATIME }, - { "noexec", MS_NOEXEC }, - { "nosuid", MS_NOSUID }, - { "nodev", MS_NODEV }, - { "nodiratime", MS_NODIRATIME }, - { "ro", MS_RDONLY }, - { "rw", 0 }, - { "remount", MS_REMOUNT }, - { "bind", MS_BIND }, - { "rec", MS_REC }, - { "unbindable", MS_UNBINDABLE }, - { "private", MS_PRIVATE }, - { "slave", MS_SLAVE }, - { "shared", MS_SHARED }, - { "defaults", 0 }, - { 0, 0 }, -}; - static bool setMountFlag(const std::string& flag, unsigned* mount_flags) { + static constexpr std::pair mount_flags_list[] = { + { "noatime", MS_NOATIME }, + { "noexec", MS_NOEXEC }, + { "nosuid", MS_NOSUID }, + { "nodev", MS_NODEV }, + { "nodiratime", MS_NODIRATIME }, + { "ro", MS_RDONLY }, + { "rw", 0 }, + { "remount", MS_REMOUNT }, + { "bind", MS_BIND }, + { "rec", MS_REC }, + { "unbindable", MS_UNBINDABLE }, + { "private", MS_PRIVATE }, + { "slave", MS_SLAVE }, + { "shared", MS_SHARED }, + { "defaults", 0 }, + }; + for (const auto& [name, value] : mount_flags_list) { if (flag == name) { *mount_flags |= value; -- cgit v1.2.3