mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 19:47:38 +00:00
Fix potential crash when traversing cpio entries
This commit is contained in:
parent
748a35774f
commit
0fcd0de0d1
@ -44,11 +44,8 @@ void magisk_cpio::patch() {
|
|||||||
fprintf(stderr, "Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]\n",
|
fprintf(stderr, "Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]\n",
|
||||||
keepverity ? "true" : "false", keepforceencrypt ? "true" : "false");
|
keepverity ? "true" : "false", keepforceencrypt ? "true" : "false");
|
||||||
|
|
||||||
auto next = entries.begin();
|
for (auto it = entries.begin(); it != entries.end();) {
|
||||||
decltype(next) cur;
|
auto cur = it++;
|
||||||
while (next != entries.end()) {
|
|
||||||
cur = next;
|
|
||||||
++next;
|
|
||||||
bool fstab = (!keepverity || !keepforceencrypt) &&
|
bool fstab = (!keepverity || !keepforceencrypt) &&
|
||||||
!str_starts(cur->first, ".backup") &&
|
!str_starts(cur->first, ".backup") &&
|
||||||
str_contains(cur->first, "fstab") && S_ISREG(cur->second->mode);
|
str_contains(cur->first, "fstab") && S_ISREG(cur->second->mode);
|
||||||
@ -140,19 +137,19 @@ for (str = (char *) buf; str < (char *) buf + size; str = str += strlen(str) + 1
|
|||||||
|
|
||||||
void magisk_cpio::restore() {
|
void magisk_cpio::restore() {
|
||||||
decompress();
|
decompress();
|
||||||
char *file;
|
|
||||||
auto next = entries.begin();
|
if (auto it = entries.find(".backup/.rmlist"); it != entries.end()) {
|
||||||
decltype(next) cur;
|
char *file;
|
||||||
while (next != entries.end()) {
|
for_each_str(file, it->second->data, it->second->filesize)
|
||||||
cur = next;
|
rm(file, false);
|
||||||
++next;
|
rm(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = entries.begin(); it != entries.end();) {
|
||||||
|
auto cur = it++;
|
||||||
if (str_starts(cur->first, ".backup")) {
|
if (str_starts(cur->first, ".backup")) {
|
||||||
if (cur->first.length() == 7 || cur->first.substr(8) == ".magisk") {
|
if (cur->first.length() == 7 || cur->first.substr(8) == ".magisk") {
|
||||||
rm(cur);
|
rm(cur);
|
||||||
} else if (cur->first.substr(8) == ".rmlist") {
|
|
||||||
for_each_str(file, cur->second->data, cur->second->filesize)
|
|
||||||
rm(file, false);
|
|
||||||
rm(cur);
|
|
||||||
} else {
|
} else {
|
||||||
mv(cur, &cur->first[8]);
|
mv(cur, &cur->first[8]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user