瀏覽代碼

Merge pull request #146 from Shopify/bugfix/argument_crash

Fixes a variable argument crash if an incorrect number of arguments are passed in
August "Gus" Mueller 12 年之前
父節點
當前提交
6decfc70c1
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      src/FMDatabase.m

+ 12 - 4
src/FMDatabase.m

@@ -665,12 +665,16 @@ - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arr
             
         while (idx < queryCount) {
             
-            if (arrayArgs) {
+            if (arrayArgs && idx < [arrayArgs count]) {
                 obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
             }
-            else {
+            else if (args) {
                 obj = va_arg(args, id);
             }
+			else {
+				//We ran out of arguments
+				break;
+			}
             
             if (_traceExecution) {
                 if ([obj isKindOfClass:[NSData class]]) {
@@ -855,12 +859,16 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
         
         while (idx < queryCount) {
             
-            if (arrayArgs) {
+            if (arrayArgs && idx < [arrayArgs count]) {
                 obj = [arrayArgs objectAtIndex:(NSUInteger)idx];
             }
-            else {
+            else if (args) {
                 obj = va_arg(args, id);
             }
+			else {
+				//We ran out of arguments
+				break;
+			}
             
             if (_traceExecution) {
                 if ([obj isKindOfClass:[NSData class]]) {