Permalink
Browse files

* Basic math is hard sometimes (fixes an issue introduced by me in b2…

…d798b)

* Fix an exception that could occur when trying to view a damaged table
* Fix a theoretical use-after-free issue by a wrongly structured retain/release in a setter
  • Loading branch information...
dmoagx committed Oct 31, 2015
1 parent 5795587 commit 2f2aafb4f5675282a37d16dce96027706096df40
@@ -87,7 +87,7 @@ - (BOOL)serverVersionIsGreaterThanOrEqualTo:(NSUInteger)aMajorVersion minorVersi
{
unsigned long myver = aMajorVersion * 10000 + aMinorVersion * 100 + aReleaseVersion;
return (myver >= serverVersionNumber);
return (serverVersionNumber >= myver);
}
#pragma mark -
@@ -471,6 +471,9 @@ - (NSString *)_getSingleVariableValue:(NSString *)variable
[result setReturnDataAsStrings:YES];
if([connection queryErrored])
SPLog(@"server variable lookup failed for '%@': %@ (%lu)",variable,[connection lastErrorMessage],[connection lastErrorID]);
if ([result numberOfRows] != 1)
return nil;
@@ -1729,20 +1729,20 @@ - (void)detectDatabaseEncoding
{
_supportsEncoding = YES;
NSString *mysqlEncoding = [databaseDataInstance getDatabaseDefaultCharacterSet];
NSString *mysqlEncoding = [[databaseDataInstance getDatabaseDefaultCharacterSet] retain];
SPClear(selectedDatabaseEncoding);
// Fallback or older version? -> set encoding to mysql default encoding latin1
if ( !mysqlEncoding ) {
NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]);
NSLog(@"Error: no character encoding found for db, mysql version is %@", [self mySQLVersion]);
selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"];
_supportsEncoding = NO;
}
else {
selectedDatabaseEncoding = [mysqlEncoding retain];
selectedDatabaseEncoding = mysqlEncoding;
}
}
@@ -434,7 +434,8 @@ - (void) setTableDetails:(NSDictionary *)tableDetails
[tableContentView scrollColumnToVisible:0];
// Set the maximum table rows to an estimated count pre-load
maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
NSString *rows = [tableDataInstance statusValueForKey:@"Rows"];
maxNumRows = (rows && ![rows isNSNull])? [rows integerValue] : 0;
maxNumRowsIsEstimate = YES;
}
@@ -3991,14 +3992,15 @@ - (void)updateNumberOfRows
[tableDataInstance updateAccurateNumberOfRowsForCurrentTableForcingUpdate:NO];
// If the state is now accurate, use it
NSString *rows = [tableDataInstance statusValueForKey:@"Rows"];
if ([[tableDataInstance statusValueForKey:@"RowsCountAccurate"] boolValue]) {
maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
maxNumRows = [rows integerValue];
maxNumRowsIsEstimate = NO;
checkStatusCount = YES;
// Otherwise, use the estimate count
} else {
maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
}
// Otherwise, use the estimate count
else {
maxNumRows = (rows && ![rows isNSNull])? [rows integerValue] : 0;
maxNumRowsIsEstimate = YES;
checkStatusCount = YES;
}
@@ -1004,7 +1004,7 @@ - (BOOL)updateStatusInformationForCurrentTable
SPOnewayAlertSheet(
NSLocalizedString(@"Error", @"error"),
[NSApp mainWindow],
[NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection lastErrorMessage]]
[NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\n\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection lastErrorMessage]]
);
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
}
@@ -1041,9 +1041,19 @@ - (BOOL)updateStatusInformationForCurrentTable
// this happens e.g. for db "information_schema"
if([[status objectForKey:@"Rows"] isNSNull]) {
tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [escapedTableName backtickQuotedString] ]];
if (![mySQLConnection queryErrored])
// this query can fail e.g. if a table is damaged
if (tableStatusResult && ![mySQLConnection queryErrored]) {
[status setObject:[[tableStatusResult getRowAsArray] objectAtIndex:0] forKey:@"Rows"];
[status setObject:@"y" forKey:@"RowsCountAccurate"];
}
else {
//FIXME that error should really show only when trying to view the table content, but we don't even try to load that if Rows==NULL
SPOnewayAlertSheet(
NSLocalizedString(@"Querying row count failed", @"table status : row count query failed : error title"),
[NSApp mainWindow],
[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to determine the number of rows for “%@”.\nMySQL said: %@ (%lu)", @"table status : row count query failed : error message"),[tableListInstance tableName],[mySQLConnection lastErrorMessage],[mySQLConnection lastErrorID]]
);
}
}
}

0 comments on commit 2f2aafb

Please sign in to comment.