Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2 security issues in the included CocoaLumberjack & also fixed 64 bit compilation #100

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Categories/DDData.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (NSString *)hexStringValue
NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([self length] * 2)];

const unsigned char *dataBuffer = [self bytes];
int i;
NSUInteger i;

for (i = 0; i < [self length]; ++i)
{
Expand Down
10 changes: 5 additions & 5 deletions Core/Mime/MultipartFormDataParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ + (NSData*) decodedDataFromData:(NSData*) data encoding:(int) encoding;
- (int) findHeaderEnd:(NSData*) workingData fromOffset:(int) offset;
- (int) findContentEnd:(NSData*) data fromOffset:(int) offset;

- (int) numberOfBytesToLeavePendingWithData:(NSData*) data length:(NSUInteger) length encoding:(int) encoding;
- (NSInteger) numberOfBytesToLeavePendingWithData:(NSData*) data length:(NSUInteger) length encoding:(int) encoding;
- (int) offsetTillNewlineSinceOffset:(int) offset inData:(NSData*) data;

- (int) processPreamble:(NSData*) workingData;
Expand Down Expand Up @@ -247,7 +247,7 @@ - (BOOL) appendData:(NSData *)data {
NSUInteger sizeToPass = workingData.length - offset - sizeToLeavePending;

// if we parse BASE64 encoded data, or Quoted-Printable data, we will make sure we don't break the format
int leaveTrailing = [self numberOfBytesToLeavePendingWithData:data length:sizeToPass encoding:currentEncoding];
NSInteger leaveTrailing = [self numberOfBytesToLeavePendingWithData:data length:sizeToPass encoding:currentEncoding];
sizeToPass -= leaveTrailing;

if( sizeToPass <= 0 ) {
Expand Down Expand Up @@ -417,14 +417,14 @@ - (int) findContentEnd:(NSData*) data fromOffset:(int) offset {
}


- (int) numberOfBytesToLeavePendingWithData:(NSData*) data length:(int) length encoding:(int) encoding {
- (NSInteger) numberOfBytesToLeavePendingWithData:(NSData*) data length:(NSUInteger) length encoding:(int) encoding {
// If we have BASE64 or Quoted-Printable encoded data, we have to be sure
// we don't break the format.
int sizeToLeavePending = 0;
NSInteger sizeToLeavePending = 0;

if( encoding == contentTransferEncoding_base64 ) {
char* bytes = (char*) data.bytes;
int i;
NSInteger i;
for( i = length - 1; i > 0; i++ ) {
if( * (uint16_t*) (bytes + i) == 0x0A0D ) {
break;
Expand Down
3 changes: 2 additions & 1 deletion Core/Mime/MultipartMessageHeaderField.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ -(BOOL) parseHeaderValueBytes:(char*) bytes length:(NSUInteger) length encoding:
HTTPLogWarn(@"MultipartFormDataParser: param %@ mentioned more then once in one header",currentParam);
}
#endif
[params setObject:paramValue forKey:currentParam];
if (paramValue)
[params setObject:paramValue forKey:currentParam];
HTTPLogVerbose(@"MultipartFormDataParser: header param: %@ = %@",currentParam,paramValue);
currentParam = nil;
}
Expand Down
7 changes: 6 additions & 1 deletion Vendor/CocoaLumberjack/DDLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@
* We also define shorthand versions for asynchronous and synchronous logging.
**/

#define LOG_MAYBE(async, lvl, flg, ctx, fnct, frmt, ...) \
/* xxx only make this need the symbols at all in debug builds */
//#ifdef DEBUG_BUILD
#define LOG_MAYBE(async, lvl, flg, ctx, fnct, frmt, ...) \
do { if(lvl & flg) LOG_MACRO(async, lvl, flg, ctx, nil, fnct, frmt, ##__VA_ARGS__); } while(0)
//#else
// #define LOG_MAYBE(async, lvl, flg, ctx, fnct, frmt, ...) {};
//#endif

#define LOG_OBJC_MAYBE(async, lvl, flg, ctx, frmt, ...) \
LOG_MAYBE(async, lvl, flg, ctx, sel_getName(_cmd), frmt, ##__VA_ARGS__)
Expand Down
7 changes: 6 additions & 1 deletion Vendor/CocoaLumberjack/DDLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ + (NSArray *)registeredClasses
// So we can allocate our buffer, and get pointers to all the class definitions.

Class *classes = (Class *)malloc(sizeof(Class) * numClasses);

if (!classes)
return nil;

numClasses = objc_getClassList(classes, numClasses);

// We can now loop through the classes, and test each one to see if it is a DDLogging class.
Expand Down Expand Up @@ -814,6 +816,9 @@ @implementation DDLogMessage

size_t length = strlen(str);
char * result = malloc(length + 1);

if (result == NULL) return NULL;

strncpy(result, str, length);
result[length] = 0;

Expand Down
42 changes: 31 additions & 11 deletions Vendor/CocoaLumberjack/DDTTYLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -835,17 +835,25 @@ - (id)init

appLen = [appName lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
app = (char *)malloc(appLen + 1);

[appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding];


if (!app)
return nil;

if (![appName getCString:app maxLength:(appLen+1) encoding:NSUTF8StringEncoding])
return nil;

// Initialize 'pid' variable (char *)

processID = [NSString stringWithFormat:@"%i", (int)getpid()];

pidLen = [processID lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
pid = (char *)malloc(pidLen + 1);

[processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding];
if (!pid)
return nil;

if (![processID getCString:pid maxLength:(pidLen+1) encoding:NSUTF8StringEncoding])
return nil;

// Initialize color stuff

Expand Down Expand Up @@ -1201,8 +1209,16 @@ - (void)logMessage:(DDLogMessage *)logMessage

char msgStack[useStack ? (msgLen + 1) : 1]; // Analyzer doesn't like zero-size array, hence the 1
char *msg = useStack ? msgStack : (char *)malloc(msgLen + 1);

[logMsg getCString:msg maxLength:(msgLen + 1) encoding:NSUTF8StringEncoding];

if (!msg)
return;

if (![logMsg getCString:msg maxLength:(msgLen + 1) encoding:NSUTF8StringEncoding]) {
if (!useStack) {
free(msg);
}
return;
}

// Write the log message to STDERR

Expand Down Expand Up @@ -1396,8 +1412,10 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo
NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
NSUInteger len2 = [fgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];

[escapeSeq getCString:(fgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
[fgCodeRaw getCString:(fgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];
if (![escapeSeq getCString:(fgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding])
return nil;
if (![fgCodeRaw getCString:(fgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding])
return nil;

fgCodeLen = len1+len2;
}
Expand Down Expand Up @@ -1430,9 +1448,11 @@ - (id)initWithForegroundColor:(OSColor *)fgColor backgroundColor:(OSColor *)bgCo
NSUInteger len1 = [escapeSeq lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
NSUInteger len2 = [bgCodeRaw lengthOfBytesUsingEncoding:NSUTF8StringEncoding];

[escapeSeq getCString:(bgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding];
[bgCodeRaw getCString:(bgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding];

if (![escapeSeq getCString:(bgCode) maxLength:(len1+1) encoding:NSUTF8StringEncoding])
return nil;
if (![bgCodeRaw getCString:(bgCode+len1) maxLength:(len2+1) encoding:NSUTF8StringEncoding])
return nil;

bgCodeLen = len1+len2;
}
else if (bgColor && isaXcodeColorTTY)
Expand Down