Use proper socket address length

This commit is contained in:
topjohnwu 2018-09-15 02:49:19 -04:00
parent af7c6f9fce
commit 2fba3f213b
2 changed files with 5 additions and 4 deletions

View File

@ -113,7 +113,7 @@ void main_daemon() {
struct sockaddr_un sun;
fd = setup_socket(&sun, MAIN_DAEMON);
if (xbind(fd, (struct sockaddr*) &sun, sizeof(sun)))
if (xbind(fd, (struct sockaddr*) &sun, sizeof(sun.sun_family) + strlen(sun.sun_path + 1) + 1))
exit(1);
xlisten(fd, 10);
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
@ -149,7 +149,8 @@ void main_daemon() {
int connect_daemon2(daemon_t d, int *sockfd) {
struct sockaddr_un sun;
*sockfd = setup_socket(&sun, d);
if (connect(*sockfd, (struct sockaddr*) &sun, sizeof(sun))) {
socklen_t len = sizeof(sun.sun_family) + strlen(sun.sun_path + 1) + 1;
if (connect(*sockfd, (struct sockaddr*) &sun, len)) {
if (getuid() != UID_ROOT || getgid() != UID_ROOT) {
fprintf(stderr, "No daemon is currently running!\n");
exit(1);
@ -168,7 +169,7 @@ int connect_daemon2(daemon_t d, int *sockfd) {
}
}
while (connect(*sockfd, (struct sockaddr*) &sun, sizeof(sun)))
while (connect(*sockfd, (struct sockaddr*) &sun, len))
usleep(10000);
return 1;
}

View File

@ -124,7 +124,7 @@ void log_daemon() {
setsid();
struct sockaddr_un sun;
sockfd = setup_socket(&sun, LOG_DAEMON);
if (xbind(sockfd, (struct sockaddr*) &sun, sizeof(sun)))
if (xbind(sockfd, (struct sockaddr*) &sun, sizeof(sun.sun_family) + strlen(sun.sun_path + 1) + 1))
exit(1);
xlisten(sockfd, 10);
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") logger started\n");