Commit 834561a5 authored by Shaka Huang's avatar Shaka Huang Committed by John Wu

Content in dt_fstab is not null terminated in emulator

Value of <dt>/fstab/<partition>/dev and <dt>/fstab/<partition>/type in official Android emulator ends with newline instead of \0, Magisk won’t be able to patch sepolicy and crash the system.
Signed-off-by: 's avatarShaka Huang <shakalaca@gmail.com>
parent 11102b4d
......@@ -97,6 +97,7 @@ static bool read_dt_fstab(cmdline *cmd, const char *name) {
if ((fd = open(path, O_RDONLY | O_CLOEXEC)) >= 0) {
read(fd, path, sizeof(path));
close(fd);
path[strcspn(path, "\r\n")] = '\0';
// Some custom treble use different names, so use what we read
char *part = rtrim(strrchr(path, '/') + 1);
sprintf(partname, "%s%s", part, strend(part, cmd->slot) ? cmd->slot : "");
......@@ -104,6 +105,7 @@ static bool read_dt_fstab(cmdline *cmd, const char *name) {
if ((fd = xopen(path, O_RDONLY | O_CLOEXEC)) >= 0) {
read(fd, fstype, 32);
close(fd);
fstype[strcspn(fstype, "\r\n")] = '\0';
return true;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment