Permalink
Browse files

Fixed a potential buffer overrun, made sure to assign to self in -ini…

…t methods, and made some types more specific; patch courtesy Sean McBride.
  • Loading branch information...
andym
andym committed Mar 5, 2008
1 parent fcf471d commit ef89e4208da03ce7181d7af20dfc13014c1b216a
@@ -21,8 +21,8 @@ @implementation NSFileManager (SUAuthenticationAdditions)
- (BOOL)currentUserOwnsPath:(NSString *)oPath
{
- char *path = (char *)[oPath fileSystemRepresentation];
- unsigned int uid = getuid();
+ const char *path = [oPath fileSystemRepresentation];
+ uid_t uid = getuid();
bool res = false;
struct stat sb;
if(stat(path, &sb) == 0)
@@ -39,11 +39,13 @@ - (BOOL)currentUserOwnsPath:(NSString *)oPath
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
- char descend[strlen(path) + 1 + entry->d_namlen + 1];
- strcpy(descend, path);
- strcat(descend, "/");
- strcat(descend, entry->d_name);
- res = [self currentUserOwnsPath:[NSString stringWithUTF8String:descend]];
+ size_t len = strlen(path) + 1 + entry->d_namlen + 1;
+ char descend[len];
+ strlcpy(descend, path, len);
+ strlcat(descend, "/", len);
+ strlcat(descend, entry->d_name, len);
+ NSString* newPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:descend length:strlen(descend)];
+ res = [self currentUserOwnsPath:newPath];
}
closedir(dir);
}
@@ -70,19 +72,19 @@ - (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst
sb.st_gid,
dst];
- AuthorizationRef auth;
+ AuthorizationRef auth = NULL;
if(AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth) == errAuthorizationSuccess)
{
char const* arguments[] = { "-c", [command fileSystemRepresentation], NULL };
- if(AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, (char**)arguments, NULL) == errAuthorizationSuccess)
+ if(AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, (char *const *)arguments, NULL) == errAuthorizationSuccess)
{
int status;
- int pid = wait(&status);
+ pid_t pid = wait(&status);
if(pid != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0)
res = YES;
}
+ AuthorizationFree(auth, 0);
}
- AuthorizationFree(auth, 0);
return res;
}
View
@@ -13,10 +13,13 @@ @implementation SUAutomaticUpdateAlert
- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb;
{
- updateItem = [item retain];
- hostBundle = [hb retain];
- [super initWithHostBundle:hb windowNibName:@"SUAutomaticUpdateAlert"];
- [self setShouldCascadeWindows:NO];
+ self = [super initWithHostBundle:hb windowNibName:@"SUAutomaticUpdateAlert"];
+ if (self)
+ {
+ updateItem = [item retain];
+ hostBundle = [hb retain];
+ [self setShouldCascadeWindows:NO];
+ }
return self;
}
@@ -127,7 +127,8 @@ - (NSComparisonResult)compareVersion:(NSString *)versionA toVersion:(NSString *)
// Yep. Lets get the next part of the larger
// n holds the index of the part we want.
NSString *missingPart;
- int missingType, shorterResult, largerResult;
+ SUCharacterType missingType;
+ NSComparisonResult shorterResult, largerResult;
if ([partsA count] > [partsB count]) {
missingPart = [partsA objectAtIndex:n];
View
@@ -13,9 +13,12 @@ @implementation SUStatusController
- (id)initWithHostBundle:(NSBundle *)hb
{
- hostBundle = [hb retain];
- [super initWithHostBundle:hb windowNibName:@"SUStatus"];
- [self setShouldCascadeWindows:NO];
+ self = [super initWithHostBundle:hb windowNibName:@"SUStatus"];
+ if (self)
+ {
+ hostBundle = [hb retain];
+ [self setShouldCascadeWindows:NO];
+ }
return self;
}
View
@@ -15,10 +15,13 @@ @implementation SUUpdateAlert
- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb
{
- hostBundle = [hb retain];
- updateItem = [item retain];
- [super initWithHostBundle:hb windowNibName:@"SUUpdateAlert"];
- [self setShouldCascadeWindows:NO];
+ self = [super initWithHostBundle:hb windowNibName:@"SUUpdateAlert"];
+ if (self)
+ {
+ hostBundle = [hb retain];
+ updateItem = [item retain];
+ [self setShouldCascadeWindows:NO];
+ }
return self;
}
View
@@ -18,12 +18,15 @@ - (BOOL)shouldAskAboutProfile
- (id)initWithHostBundle:(NSBundle *)hb delegate:(id)d
{
- hostBundle = [hb retain];
- delegate = [d retain];
- isShowingMoreInfo = NO;
- shouldSendProfile = [self shouldAskAboutProfile];
- [super initWithHostBundle:hb windowNibName:@"SUUpdatePermissionPrompt"];
- [self setShouldCascadeWindows:NO];
+ self = [super initWithHostBundle:hb windowNibName:@"SUUpdatePermissionPrompt"];
+ if (self)
+ {
+ hostBundle = [hb retain];
+ delegate = [d retain];
+ isShowingMoreInfo = NO;
+ shouldSendProfile = [self shouldAskAboutProfile];
+ [self setShouldCascadeWindows:NO];
+ }
return self;
}

0 comments on commit ef89e42

Please sign in to comment.