From c981907f369910f894c818d15beebd5d7113dd67 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Thu, 15 Aug 2024 20:35:38 -0300 Subject: [PATCH] fix: using fgets in a file descriptor This commit fixes the use of fgets in a file descriptor, which would make it easier to use fopen instead of using fdopen. --- zygiskd/src/utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zygiskd/src/utils.c b/zygiskd/src/utils.c index 9fc5b9f..5527f6d 100644 --- a/zygiskd/src/utils.c +++ b/zygiskd/src/utils.c @@ -58,7 +58,7 @@ void set_socket_create_context(const char *context) { return; } - if (write(context, 1, strlen(context), sockcreate) != strlen(context)) { + if (write(sockcreate, context, strlen(context)) != (ssize_t)strlen(context)) { LOGE("fwrite: %s\n", strerror(errno)); errno = 0; @@ -72,15 +72,15 @@ static void get_current_attr(char *output) { char path[PATH_MAX]; snprintf(path, PATH_MAX, "/proc/self/attr/current"); - int current = open(path, O_RDONLY | O_CLOEXEC); - if (current == -1) { + FILE *current = fopen(path, "r"); + if (current == NULL) { LOGE("Failed to open current: %s\n", strerror(errno)); errno = 0; return; } - if (fgets(output, PATH_MAX, fileno(current)) == NULL) { + if (fgets(output, PATH_MAX, current) == NULL) { LOGE("fgets: %s\n", strerror(errno)); errno = 0;