Skip to content

Commit

Permalink
Use a C formatting function for a C string
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 28, 2015
1 parent c61b5d9 commit bac2463
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Sparkle/SUFileManager.m
Expand Up @@ -483,13 +483,10 @@ - (BOOL)changeOwnerAndGroupOfItemAtRootURL:(NSURL *)targetURL toMatchURL:(NSURL
return NO;
}

NSString *formattedUserAndGroupIDs = [NSString stringWithFormat:@"%u:%u", ownerID.unsignedIntValue, groupID.unsignedIntValue];
char userAndGroup[PATH_MAX] = {0};
if (![formattedUserAndGroupIDs getFileSystemRepresentation:userAndGroup maxLength:sizeof(userAndGroup)]) {
if (error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFormattingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Owner ID %u and Group ID %u could not be formatted.", ownerID.unsignedIntValue, groupID.unsignedIntValue] }];
}
return NO;
char userAndGroup[100];
int written = snprintf(userAndGroup, sizeof(userAndGroup), "%u:%u", ownerID.unsignedIntValue, groupID.unsignedIntValue);
if (written < 0 || written >= 100) {
return NO; // No custom error, because it's too unlikely to ever happen
}

if (![self _acquireAuthorizationWithError:error]) {
Expand All @@ -498,7 +495,7 @@ - (BOOL)changeOwnerAndGroupOfItemAtRootURL:(NSURL *)targetURL toMatchURL:(NSURL

BOOL success = AuthorizationExecuteWithPrivilegesAndWait(_auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, (char *[]){ "-R", userAndGroup, targetPath, NULL });
if (!success && error != NULL) {
NSString *errorMessage = [NSString stringWithFormat:@"Failed to change owner:group %@ on %@ with authentication.", formattedUserAndGroupIDs, targetURL.path.lastPathComponent];
NSString *errorMessage = [NSString stringWithFormat:@"Failed to change owner:group %@ on %@ with authentication.", [NSString stringWithUTF8String:userAndGroup], targetURL.path.lastPathComponent];
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
}

Expand Down

0 comments on commit bac2463

Please sign in to comment.