[AltServer] Fixes potential double-free bug when finishing installing

This commit is contained in:
Riley Testut
2019-05-31 11:23:18 -07:00
parent d1fc207bf6
commit 23e019ebcf

View File

@@ -57,7 +57,7 @@ NSErrorDomain const ALTDeviceErrorDomain = @"com.rileytestut.ALTDeviceError";
NSProgress *progress = [NSProgress discreteProgressWithTotalUnitCount:100]; NSProgress *progress = [NSProgress discreteProgressWithTotalUnitCount:100];
NSUUID *UUID = [NSUUID UUID]; NSUUID *UUID = [NSUUID UUID];
char *uuidString = (char *)malloc(UUID.UUIDString.length + 1); __block char *uuidString = (char *)malloc(UUID.UUIDString.length + 1);
strncpy(uuidString, (const char *)UUID.UUIDString.UTF8String, UUID.UUIDString.length); strncpy(uuidString, (const char *)UUID.UUIDString.UTF8String, UUID.UUIDString.length);
uuidString[UUID.UUIDString.length] = '\0'; uuidString[UUID.UUIDString.length] = '\0';
@@ -77,6 +77,7 @@ NSErrorDomain const ALTDeviceErrorDomain = @"com.rileytestut.ALTDeviceError";
lockdownd_service_descriptor_free(service); lockdownd_service_descriptor_free(service);
free(uuidString); free(uuidString);
uuidString = NULL;
if (error != nil) if (error != nil)
{ {
@@ -149,7 +150,7 @@ NSErrorDomain const ALTDeviceErrorDomain = @"com.rileytestut.ALTDeviceError";
np_set_notify_callback(np, ALTDeviceManagerDidFinishAppInstallation, uuidString); np_set_notify_callback(np, ALTDeviceManagerDidFinishAppInstallation, uuidString);
const char *notifications[3] = { NP_APP_INSTALLED, NP_APP_UNINSTALLED, NULL }; const char *notifications[2] = { NP_APP_INSTALLED, NULL };
np_observe_notifications(np, notifications); np_observe_notifications(np, notifications);
if (service) if (service)
@@ -426,9 +427,9 @@ NSErrorDomain const ALTDeviceErrorDomain = @"com.rileytestut.ALTDeviceError";
#pragma mark - Callbacks - #pragma mark - Callbacks -
void ALTDeviceManagerDidFinishAppInstallation(const char *notification, void *udid) void ALTDeviceManagerDidFinishAppInstallation(const char *notification, void *uuid)
{ {
NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:[NSString stringWithUTF8String:(const char *)udid]]; NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:[NSString stringWithUTF8String:(const char *)uuid]];
void (^completionHandler)(void) = ALTDeviceManager.sharedManager.installationCompletionHandlers[UUID]; void (^completionHandler)(void) = ALTDeviceManager.sharedManager.installationCompletionHandlers[UUID];
if (completionHandler != nil) if (completionHandler != nil)
@@ -439,9 +440,9 @@ void ALTDeviceManagerDidFinishAppInstallation(const char *notification, void *ud
} }
} }
void ALTDeviceManagerUpdateStatus(plist_t command, plist_t status, void *udid) void ALTDeviceManagerUpdateStatus(plist_t command, plist_t status, void *uuid)
{ {
NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:[NSString stringWithUTF8String:(const char *)udid]]; NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:[NSString stringWithUTF8String:(const char *)uuid]];
NSProgress *progress = ALTDeviceManager.sharedManager.installationProgress[UUID]; NSProgress *progress = ALTDeviceManager.sharedManager.installationProgress[UUID];
if (progress == nil) if (progress == nil)
@@ -455,7 +456,7 @@ void ALTDeviceManagerUpdateStatus(plist_t command, plist_t status, void *udid)
if (progress.completedUnitCount < percent) if (progress.completedUnitCount < percent)
{ {
progress.completedUnitCount = percent; progress.completedUnitCount = percent;
NSLog(@"Installation Progress: %@", @(percent));
} }
NSLog(@"Installation Progress: %@", @(percent));
} }