mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-09 19:56:04 -08:00
Guard su request IPC
Previously `read_string()` calls `std::string.resize()` with a int read from remote process. When I/O error occurs, -1 will be used for resizing the string, `std::bad_alloc` is thrown and since magisk is compiled with `-fno-exceptions`, it will crash the whole daemon process. May fix topjohnwu#5681
This commit is contained in:
@@ -158,11 +158,13 @@ void write_int_be(int fd, int val) {
|
||||
xwrite(fd, &nl, sizeof(nl));
|
||||
}
|
||||
|
||||
void read_string(int fd, std::string &str) {
|
||||
bool read_string(int fd, std::string &str) {
|
||||
int len = read_int(fd);
|
||||
str.clear();
|
||||
if (len < 0)
|
||||
return false;
|
||||
str.resize(len);
|
||||
xxread(fd, str.data(), len);
|
||||
return xxread(fd, str.data(), len) == len;
|
||||
}
|
||||
|
||||
string read_string(int fd) {
|
||||
|
||||
Reference in New Issue
Block a user