Fixed a potential buffer overrun, made sure to assign to self in -init methods, and made some types more specific; patch courtesy Sean McBride.

This commit is contained in:
andym committed 2008-03-05 14:07:43 +00:00
1 parent fcf471d08f
commit ef89e4208d
6 files changed
+44 -29

No files matched your search

+13 -11
View File
@@ -21,8 +21,8 @@
- (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 @@
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 @@
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;
}
+7 -4
View File
@@ -13,10 +13,13 @@
- (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;
}
+2 -1
View File
@@ -127,7 +127,8 @@ typedef enum {
// 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];
+6 -3
View File
@@ -13,9 +13,12 @@
- (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;
}
+7 -4
View File
@@ -15,10 +15,13 @@
- (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;
}
+9 -6
View File
@@ -18,12 +18,15 @@
- (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;
}