Skip to content

Commit

Permalink
fix(crypto): check if NSData is null terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
QHivert committed Feb 12, 2024
1 parent 26f05a6 commit 5197b9b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion SoObjects/SOGo/NSString+Crypto.m
Expand Up @@ -660,7 +660,16 @@ - (NSString *)decryptAES256GCM:(NSString *)passwordScheme iv:(NSString *)ivStrin

if (rv > 0) {
if (outputData) {
value = [NSString stringWithUTF8String: [outputData bytes]];
char lastByte;
[outputData getBytes:&lastByte range:NSMakeRange([outputData length]-1, 1)];
if (lastByte == 0x0) {
// string is null terminated
value = [NSString stringWithUTF8String: [outputData bytes]];
} else {
// string is not null terminated
value = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
[value autorelease];
}
} else {
*ex = [NSException exceptionWithName: kAES256GCMError reason:@"Decryption ok but output empty" userInfo: nil];
}
Expand Down

0 comments on commit 5197b9b

Please sign in to comment.