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: Shaka Huang <shakalaca@gmail.com>
This commit is contained in:
Shaka Huang 2020-03-27 14:56:49 +08:00 committed by John Wu
parent 11102b4dd6
commit 834561a5de

View File

@ -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;
}
}