You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
fix: fd leak and out-of-bounds access in exec_command
This commit fixes both fd leak and out-of-bounds access in the "exec_command" function, which can happen when execution of the command fails, leading to crashes on Magisk-rooted devices, and possibly APatch-rooted devices too.
This commit is contained in:
@@ -347,6 +347,9 @@ bool exec_command(char *restrict buf, size_t len, const char *restrict file, cha
|
|||||||
if ((pid = fork()) == -1) {
|
if ((pid = fork()) == -1) {
|
||||||
LOGE("fork: %s\n", strerror(errno));
|
LOGE("fork: %s\n", strerror(errno));
|
||||||
|
|
||||||
|
close(link[0]);
|
||||||
|
close(link[1]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,13 +359,20 @@ bool exec_command(char *restrict buf, size_t len, const char *restrict file, cha
|
|||||||
close(link[1]);
|
close(link[1]);
|
||||||
|
|
||||||
execv(file, argv);
|
execv(file, argv);
|
||||||
|
|
||||||
|
LOGE("execv failed: %s\n", strerror(errno));
|
||||||
|
_exit(1);
|
||||||
} else {
|
} else {
|
||||||
close(link[1]);
|
close(link[1]);
|
||||||
|
|
||||||
int nbytes = read(link[0], buf, len);
|
int nbytes = read(link[0], buf, len);
|
||||||
buf[nbytes - 1] = '\0';
|
if (nbytes > 0) buf[nbytes - 1] = '\0';
|
||||||
|
/* INFO: If something went wrong, at least we must ensure it is NULL-terminated */
|
||||||
|
else buf[0] = '\0';
|
||||||
|
|
||||||
wait(NULL);
|
wait(NULL);
|
||||||
|
|
||||||
|
close(link[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user