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
This commit is contained in:
parent
1055a2f07a
commit
1dfb086ca8
1 changed files with 18 additions and 22 deletions
|
@ -44,10 +44,8 @@ std::string UpdaterRuntime::FindBlockDeviceName(const std::string_view name) con
|
||||||
return std::string(name);
|
return std::string(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static bool setMountFlag(const std::string& flag, unsigned* mount_flags) {
|
||||||
const char* name;
|
static constexpr std::pair<const char*, unsigned> mount_flags_list[] = {
|
||||||
unsigned flag;
|
|
||||||
} mount_flags_list[] = {
|
|
||||||
{ "noatime", MS_NOATIME },
|
{ "noatime", MS_NOATIME },
|
||||||
{ "noexec", MS_NOEXEC },
|
{ "noexec", MS_NOEXEC },
|
||||||
{ "nosuid", MS_NOSUID },
|
{ "nosuid", MS_NOSUID },
|
||||||
|
@ -63,10 +61,8 @@ static struct {
|
||||||
{ "slave", MS_SLAVE },
|
{ "slave", MS_SLAVE },
|
||||||
{ "shared", MS_SHARED },
|
{ "shared", MS_SHARED },
|
||||||
{ "defaults", 0 },
|
{ "defaults", 0 },
|
||||||
{ 0, 0 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool setMountFlag(const std::string& flag, unsigned* mount_flags) {
|
|
||||||
for (const auto& [name, value] : mount_flags_list) {
|
for (const auto& [name, value] : mount_flags_list) {
|
||||||
if (flag == name) {
|
if (flag == name) {
|
||||||
*mount_flags |= value;
|
*mount_flags |= value;
|
||||||
|
|
Loading…
Reference in a new issue