diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 3bf8d24f..113a8017 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -32,21 +32,33 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, arguments, NULL) == errAuthorizationSuccess) + if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, arguments, NULL) == errAuthorizationSuccess) { #pragma clang diagnostic pop - { - int status = 0; - pid_t pid = 0; - - do { - pid = wait(&status); - } while (pid == -1 && errno == EINTR); - - if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) - returnValue = NO; - } - else + // Wait for every child to finish termination because we won't know which particular child is ours. + // Perhaps in the future writing a custom wrapper tool that communicates its pid in stdout may be a better route + // However that has the security issue of anyone being able to swap in our tool with their own + // Another possible idea is using sh -c and echo'ing the pid which we read from here, then executing our command, + // but we would have to be careful about sanitizing paths, \ escaping quotation marks, ... + while (true) { + pid_t waitPid = 0; + int waitStatus = 0; + + waitPid = wait(&waitStatus); + if (waitPid != -1 || errno == EINTR) { + // Continue and wait for all children to terminate + } else { + if (errno != ECHILD) { + // Ran into an abnormal error + returnValue = NO; + } + break; + } + } + // We can't check the status from wait() here because the child whose status we check may not be the child we are responsible for + // So we will assume that the process terminated successfully; I know, not ideal. + } else { returnValue = NO; + } return returnValue; }