Fix bug in MagiskBoot

This commit is contained in:
topjohnwu 2018-10-26 17:02:07 -04:00
parent 958d6377e3
commit 6add02702b
3 changed files with 19 additions and 11 deletions

View File

@ -211,9 +211,10 @@ bool cpio::mv(const char *from, const char *to) {
delete arr[t]; delete arr[t];
arr[t] = nullptr; arr[t] = nullptr;
} }
free(arr[f]->filename);
arr[f]->filename = strdup(to);
fprintf(stderr, "Move [%s] -> [%s]\n", from, to); fprintf(stderr, "Move [%s] -> [%s]\n", from, to);
char * tmp = strdup(to);
free(arr[f]->filename);
arr[f]->filename = tmp;
return true; return true;
} }
fprintf(stderr, "Cannot find entry %s\n", from); fprintf(stderr, "Cannot find entry %s\n", from);

View File

@ -24,20 +24,20 @@ struct cpio_newc_header {
struct cpio_entry { struct cpio_entry {
// uint32_t ino; // uint32_t ino;
uint32_t mode; uint32_t mode = 0;
uint32_t uid; uint32_t uid = 0;
uint32_t gid; uint32_t gid = 0;
// uint32_t nlink; // uint32_t nlink;
// uint32_t mtime; // uint32_t mtime;
uint32_t filesize; uint32_t filesize = 0;
// uint32_t devmajor; // uint32_t devmajor;
// uint32_t devminor; // uint32_t devminor;
// uint32_t rdevmajor; // uint32_t rdevmajor;
// uint32_t rdevminor; // uint32_t rdevminor;
// uint32_t namesize; // uint32_t namesize;
// uint32_t check; // uint32_t check;
char *filename; char *filename = nullptr;
void *data; void *data = nullptr;
cpio_entry() {} cpio_entry() {}
cpio_entry(int fd, cpio_newc_header &header); cpio_entry(int fd, cpio_newc_header &header);

View File

@ -208,10 +208,17 @@ int cpio_commands(int argc, char *argv[]) {
char *cmdv[6]; char *cmdv[6];
while (argc) { while (argc) {
// Clean up
cmdc = 0; cmdc = 0;
for (char *tok = strtok(argv[0], " "); tok; tok = strtok(NULL, " ")) memset(cmdv, NULL, sizeof(cmdv));
// Split the commands
for (char *tok = strtok(argv[0], " "); tok; tok = strtok(nullptr, " "))
cmdv[cmdc++] = tok; cmdv[cmdc++] = tok;
if (cmdc == 0)
continue;
if (strcmp(cmdv[0], "test") == 0) { if (strcmp(cmdv[0], "test") == 0) {
exit(cpio.test()); exit(cpio.test());
} else if (strcmp(cmdv[0], "restore") == 0) { } else if (strcmp(cmdv[0], "restore") == 0) {
@ -224,13 +231,13 @@ int cpio_commands(int argc, char *argv[]) {
return 0; return 0;
} else if (cmdc >= 2 && strcmp(cmdv[0], "backup") == 0) { } else if (cmdc >= 2 && strcmp(cmdv[0], "backup") == 0) {
auto bak = Array<cpio_entry*>(); auto bak = Array<cpio_entry*>();
cpio.backup(bak, cmdv[1], cmdc > 2 ? cmdv[2] : nullptr); cpio.backup(bak, cmdv[1], cmdv[2]);
cpio.insert(bak); cpio.insert(bak);
} else if (cmdc >= 4 && strcmp(cmdv[0], "magisk") == 0) { } else if (cmdc >= 4 && strcmp(cmdv[0], "magisk") == 0) {
cpio.patch(strcmp(cmdv[2], "true") == 0, strcmp(cmdv[3], "true") == 0); cpio.patch(strcmp(cmdv[2], "true") == 0, strcmp(cmdv[3], "true") == 0);
auto bak = Array<cpio_entry*>(); auto bak = Array<cpio_entry*>();
cpio.backup(bak, cmdv[1], cmdc > 4 ? cmdv[4] : nullptr); cpio.backup(bak, cmdv[1], cmdv[4]);
auto e = new cpio_entry(); auto e = new cpio_entry();
e->filename = strdup(".backup/.magisk"); e->filename = strdup(".backup/.magisk");