Fix some potential crashes and memory leaks.
This commit is contained in:
parent
a72d893203
commit
ba00d89b99
@ -54,8 +54,10 @@ void mpw_pushInt(uint8_t **const buffer, size_t *const bufferSize, const uint32_
|
|||||||
|
|
||||||
void mpw_free(const void *buffer, const size_t bufferSize) {
|
void mpw_free(const void *buffer, const size_t bufferSize) {
|
||||||
|
|
||||||
memset( (void *)buffer, 0, bufferSize );
|
if (buffer) {
|
||||||
free( (void *)buffer );
|
memset( (void *)buffer, 0, bufferSize );
|
||||||
|
free( (void *)buffer );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpw_freeString(const char *string) {
|
void mpw_freeString(const char *string) {
|
||||||
|
@ -140,10 +140,12 @@ NSOperationQueue *_mpwQueue = nil;
|
|||||||
[self mpw_perform:^{
|
[self mpw_perform:^{
|
||||||
NSDate *start = [NSDate date];
|
NSDate *start = [NSDate date];
|
||||||
uint8_t const *masterKeyBytes = mpw_masterKeyForUser( fullName.UTF8String, masterPassword.UTF8String, [self version] );
|
uint8_t const *masterKeyBytes = mpw_masterKeyForUser( fullName.UTF8String, masterPassword.UTF8String, [self version] );
|
||||||
keyData = [NSData dataWithBytes:masterKeyBytes length:MP_dkLen];
|
if (masterKeyBytes) {
|
||||||
trc( @"User: %@, password: %@ derives to key ID: %@ (took %0.2fs)", //
|
keyData = [NSData dataWithBytes:masterKeyBytes length:MP_dkLen];
|
||||||
fullName, masterPassword, [self keyIDForKeyData:keyData], -[start timeIntervalSinceNow] );
|
trc( @"User: %@, password: %@ derives to key ID: %@ (took %0.2fs)", //
|
||||||
mpw_free( masterKeyBytes, MP_dkLen );
|
fullName, masterPassword, [self keyIDForKeyData:keyData], -[start timeIntervalSinceNow] );
|
||||||
|
mpw_free( masterKeyBytes, MP_dkLen );
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return keyData;
|
return keyData;
|
||||||
@ -358,8 +360,10 @@ NSOperationQueue *_mpwQueue = nil;
|
|||||||
[self mpw_perform:^{
|
[self mpw_perform:^{
|
||||||
char const *contentBytes = mpw_passwordForSite( [key keyDataForAlgorithm:self].bytes,
|
char const *contentBytes = mpw_passwordForSite( [key keyDataForAlgorithm:self].bytes,
|
||||||
name.UTF8String, type, (uint32_t)counter, variant, context.UTF8String, [self version] );
|
name.UTF8String, type, (uint32_t)counter, variant, context.UTF8String, [self version] );
|
||||||
content = [NSString stringWithCString:contentBytes encoding:NSUTF8StringEncoding];
|
if (contentBytes) {
|
||||||
mpw_freeString( contentBytes );
|
content = [NSString stringWithCString:contentBytes encoding:NSUTF8StringEncoding];
|
||||||
|
mpw_freeString( contentBytes );
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
|
@ -26,7 +26,7 @@ static NSDictionary *createKeyQuery(MPUserEntity *user, BOOL newItem, MPKeyOrigi
|
|||||||
*keyOrigin = MPKeyOriginKeyChainBiometric;
|
*keyOrigin = MPKeyOriginKeyChainBiometric;
|
||||||
|
|
||||||
CFErrorRef acError = NULL;
|
CFErrorRef acError = NULL;
|
||||||
SecAccessControlRef accessControl = SecAccessControlCreateWithFlags( kCFAllocatorDefault,
|
id accessControl = (__bridge_transfer id)SecAccessControlCreateWithFlags( kCFAllocatorDefault,
|
||||||
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, kSecAccessControlTouchIDCurrentSet, &acError );
|
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, kSecAccessControlTouchIDCurrentSet, &acError );
|
||||||
if (!accessControl || acError)
|
if (!accessControl || acError)
|
||||||
err( @"Could not use TouchID on this device: %@", acError );
|
err( @"Could not use TouchID on this device: %@", acError );
|
||||||
@ -36,7 +36,7 @@ static NSDictionary *createKeyQuery(MPUserEntity *user, BOOL newItem, MPKeyOrigi
|
|||||||
attributes:@{
|
attributes:@{
|
||||||
(__bridge id)kSecAttrService : @"Saved Master Password",
|
(__bridge id)kSecAttrService : @"Saved Master Password",
|
||||||
(__bridge id)kSecAttrAccount : user.name?: @"",
|
(__bridge id)kSecAttrAccount : user.name?: @"",
|
||||||
(__bridge id)kSecAttrAccessControl : (__bridge id)accessControl,
|
(__bridge id)kSecAttrAccessControl : accessControl,
|
||||||
(__bridge id)kSecUseAuthenticationUI : (__bridge id)kSecUseAuthenticationUIAllow,
|
(__bridge id)kSecUseAuthenticationUI : (__bridge id)kSecUseAuthenticationUIAllow,
|
||||||
(__bridge id)kSecUseOperationPrompt :
|
(__bridge id)kSecUseOperationPrompt :
|
||||||
strf( @"Access %@'s master password.", user.name ),
|
strf( @"Access %@'s master password.", user.name ),
|
||||||
|
@ -31,76 +31,26 @@
|
|||||||
#import <objc/NSObjCRuntime.h>
|
#import <objc/NSObjCRuntime.h>
|
||||||
#import <stdlib.h>
|
#import <stdlib.h>
|
||||||
|
|
||||||
#define trc(format, ...) \
|
#define log(level, format, ...) \
|
||||||
do { \
|
do { \
|
||||||
|
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
||||||
char *_msg = NULL; \
|
char *_msg = NULL; \
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
CFStringRef fileStr = CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ); \
|
||||||
|
CFStringRef funcStr = CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ); \
|
||||||
|
CFStringRef msgStr = CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ); \
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), fileStr, __LINE__, funcStr, level, msgStr ); \
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
CFRelease( fileStr ); \
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 0, \
|
CFRelease( funcStr ); \
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
CFRelease( msgStr ); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define dbg(format, ...) \
|
#define trc(format, ...) log( 0, format, ##__VA_ARGS__ );
|
||||||
do { \
|
#define dbg(format, ...) log( 1, format, ##__VA_ARGS__ );
|
||||||
char *_msg = NULL; \
|
#define inf(format, ...) log( 2, format, ##__VA_ARGS__ );
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
#define wrn(format, ...) log( 3, format, ##__VA_ARGS__ );
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
#define err(format, ...) log( 4, format, ##__VA_ARGS__ );
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
#define ftl(format, ...) log( 5, format, ##__VA_ARGS__ );
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 1, \
|
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define inf(format, ...) \
|
|
||||||
do { \
|
|
||||||
char *_msg = NULL; \
|
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 2, \
|
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define wrn(format, ...) \
|
|
||||||
do { \
|
|
||||||
char *_msg = NULL; \
|
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 3, \
|
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define err(format, ...) \
|
|
||||||
do { \
|
|
||||||
char *_msg = NULL; \
|
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 4, \
|
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define ftl(format, ...) \
|
|
||||||
do { \
|
|
||||||
char *_msg = NULL; \
|
|
||||||
asprintf( &_msg, format, ##__VA_ARGS__ ); \
|
|
||||||
void (*_sendMsg)(id, SEL, CFStringRef, NSInteger, CFStringRef, NSUInteger, CFStringRef) = (void *)objc_msgSend; \
|
|
||||||
_sendMsg( objc_msgSend( (id)objc_getClass( "PearlLogger" ), sel_getUid( "get" ) ), \
|
|
||||||
sel_getUid( "inFile:atLine:fromFunction:withLevel:text:" ), \
|
|
||||||
CFStringCreateWithCString( NULL, basename( (char *)__FILE__ ), kCFStringEncodingUTF8 ), __LINE__, \
|
|
||||||
CFStringCreateWithCString( NULL, __FUNCTION__, kCFStringEncodingUTF8 ), 5, \
|
|
||||||
CFStringCreateWithCString( NULL, _msg, kCFStringEncodingUTF8 ) ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user