Skip to content
Snippets Groups Projects
Commit 8a05152b authored by Esben Haabendal's avatar Esben Haabendal
Browse files

prebuilts: Fix segfault in e2fsdroid command


This backports all fixes from OpenHarmony 3.1.1, which avoids random segfaults
in e2fsdroid.

Signed-off-by: default avatarEsben Haabendal <esben.haabendal@huawei.com>
parent 597003be
No related branches found
No related tags found
1 merge request!20CI: Test toolchain and bundle images against OHOS codebase
......@@ -15,3 +15,4 @@ SRC_URI += "file://patches/foundation_graphic_standard.patch;apply=no;subdir=src
SRC_URI += "file://patches/productdefine_common.patch;apply=no;subdir=src"
SRC_URI += "file://patches/third_party_libevdev.patch;apply=no;subdir=src"
SRC_URI += "file://patches/third_party_libusb.patch;apply=no;subdir=src"
SRC_URI += "file://patches/third_party_e2fsprogs-backports-to-3.1.patch;apply=no;subdir=src"
# SPDX-FileCopyrightText: Huawei Inc.
#
# SPDX-License-Identifier: Apache-2.0
Backport of fixes included in OpenHarmony-v3.1.1 release
f1f1a3471fdf - Fix CodeCheck warning.
00663d8aab61 - static_cast size_t to int
97aa5de11e0d - Pass parameter p by reference.
6758af0c0da8 - Fix the crash problem caused by overflow in GetDacConfig.
Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
Upstream-Status: Backport
diff --git a/third_party/e2fsprogs/contrib/android/dac_config.cpp b/third_party/e2fsprogs/contrib/android/dac_config.cpp
index 422e0d52280f..1c76dfd7e7d1 100644
--- a/third_party/e2fsprogs/contrib/android/dac_config.cpp
+++ b/third_party/e2fsprogs/contrib/android/dac_config.cpp
@@ -35,14 +35,14 @@ struct DacConfig {
string path;
DacConfig() : uid(0), gid(0), mode(0), capabilities(0), path("") {}
- DacConfig(unsigned int m, unsigned int u, unsigned int g, uint64_t c, string p) :
+ DacConfig(unsigned int m, unsigned int u, unsigned int g, uint64_t c, const string &p) :
uid(u),
gid(g),
mode(m),
capabilities(c),
path(p) {}
- void SetDefault(unsigned int m, unsigned int u, unsigned int g, uint64_t c, string p)
+ void SetDefault(unsigned int m, unsigned int u, unsigned int g, uint64_t c, const string &p)
{
this->uid = u;
this->gid = g;
@@ -198,33 +198,28 @@ extern "C" {
return 0;
}
- void GetDacConfig(const char* path, int dir, char* targetOutPath,
+ void GetDacConfig(const char* path, int dir, char*,
unsigned* uid, unsigned* gid, unsigned* mode,
uint64_t* capabilities)
{
- if (path && path[0] == '/') {
- path++;
- }
-
- (void)targetOutPath;
- string str = path;
- string str2;
+ string str = (path != nullptr && *path == '/') ? path + 1 : path;
DacConfig dacConfig(00755, 0, 0, 0, "");
if (dir == 0) {
dacConfig.SetDefault(00644, 0, 0, 0, "");
}
- if (g_configMap.count(str)) {
- dacConfig = g_configMap[str];
+ auto it = g_configMap.find(str);
+ if (it != g_configMap.end()) {
+ dacConfig = it->second;
} else if (dir == 0 && !str.empty()) {
- for (auto i = str.size() - 1; i >= 0; i--) {
+ for (int i = static_cast<int>(str.size()) - 1; i >= 0; i--) {
if (str[i] == '/') {
break;
} else {
- str2 = str.substr(0, i) + "*";
- if (g_configMap.count(str2)) {
- dacConfig = g_configMap[str2];
+ it = g_configMap.find(str.substr(0, i) + "*");
+ if (it != g_configMap.end()) {
+ dacConfig = it->second;
break;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment