From 834561a5de301fbbbe85deb8fccd3b093a47c830 Mon Sep 17 00:00:00 2001 From: Shaka Huang Date: Fri, 27 Mar 2020 14:56:49 +0800 Subject: [PATCH] Content in dt_fstab is not null terminated in emulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Value of
/fstab//dev and
/fstab//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 --- native/jni/init/mount.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/jni/init/mount.cpp b/native/jni/init/mount.cpp index cace570ce..82bae2ba2 100644 --- a/native/jni/init/mount.cpp +++ b/native/jni/init/mount.cpp @@ -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; } }