Commit 0ecfb63c authored by Shaka Huang's avatar Shaka Huang Committed by John Wu

Fix crash during boot in x86 platform

readlinkat() may return random value instead of the number of bytes placed in buf and crashing the system in two ways:
1. segmentation fault (buf[-7633350] = ‘\0’)
2. wrong link of watchdogd, resulting dog timeout

Confirmed working in ZenFone 2 x86 series, may fix #2247 and #2356
Signed-off-by: 's avatarShaka Huang <shakalaca@gmail.com>
parent ebdd6ec4
...@@ -217,7 +217,14 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) { ...@@ -217,7 +217,14 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) {
struct stat st; struct stat st;
fstatat(src, entry->d_name, &st, AT_SYMLINK_NOFOLLOW); fstatat(src, entry->d_name, &st, AT_SYMLINK_NOFOLLOW);
if (S_ISLNK(st.st_mode)) { if (S_ISLNK(st.st_mode)) {
#if defined(__i386__)
// readlinkat() may failed on x86 platform, returning random value
// instead of number of bytes placed in buf (length of link)
memset(buf, 0, sizeof(buf));
readlinkat(src, entry->d_name, buf, sizeof(buf));
#else
xreadlinkat(src, entry->d_name, buf, sizeof(buf)); xreadlinkat(src, entry->d_name, buf, sizeof(buf));
#endif
xsymlink(buf, sbin_path.data()); xsymlink(buf, sbin_path.data());
} else { } else {
sprintf(buf, "%s/%s", mirror, entry->d_name); sprintf(buf, "%s/%s", mirror, entry->d_name);
......
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