improve: module.prop parsing code; fix: deferecing a NULL pointer

This commit both improves the code that parses "module.prop" file of ReZygisk, reducing its complexity greatly and also making it smaller, and also fixes an issue where ReZygisk would deference a NULL pointer, leading to crashes in Zygiskd crash.
This commit is contained in:
ThePedroo
2024-11-08 17:32:55 -03:00
parent 66e98cf007
commit 2c74ee3877

View File

@@ -445,8 +445,16 @@ static bool ensure_daemon_created(bool is_64bit) {
LOGW("daemon" #abi " pid %d exited: %s", pid, status_str); \
status##abi.daemon_running = false; \
\
if (status##abi.daemon_error_info[0] == '\0') \
memcpy(status##abi.daemon_error_info, status_str, strlen(status_str)); \
if (!status##abi.daemon_error_info) { \
status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \
if (status##abi.daemon_error_info) { \
LOGE("malloc daemon" #abi " error info failed"); \
\
return; \
} \
\
memcpy(status##abi.daemon_error_info, status_str, strlen(status_str) + 1); \
} \
\
updateStatus(); \
continue; \
@@ -822,26 +830,27 @@ static bool prepare_environment() {
return false;
}
const char field_name[] = "description=";
int pre_section_len = 0;
int post_section_len = 0;
bool after_description = false;
char line[1024];
while (fgets(line, sizeof(line), orig_prop) != NULL) {
if (strstr(line, field_name) == line) {
strncat(pre_section, "description=", sizeof(pre_section) - pre_section_len);
if (strncmp(line, "description=", strlen("description=")) == 0) {
strcat(pre_section, "description=");
strcat(post_section, line + strlen("description="));
after_description = true;
pre_section_len += strlen("description=");
} else {
strncat(post_section, line, sizeof(post_section) - post_section_len);
post_section_len += strlen(line);
continue;
}
if (after_description) strcat(post_section, line);
else strcat(pre_section, line);
}
fclose(orig_prop);
/* TODO: See if ZYGISK_ENABLED flag is already set,
if so, set a status saying to disable built-in Zygisk. */
A
updateStatus();
return true;