summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-02-26 13:35:59 -0500
committerJoel Fischer <joeljfischer@gmail.com>2019-02-26 13:35:59 -0500
commit393b28220bdefa8b931acfcf54f383ff7cc58051 (patch)
treec0cc3d98dfa16b33d50cc1c1b1e74f33d279a475
parentecad23fc122eae207a0933b051ec16535a7094cb (diff)
downloadsdl_ios-feature/issue_1142_block_old_sdl.tar.gz
Prevent negative string numbers from being usedfeature/issue_1142_block_old_sdl
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj16
-rw-r--r--SmartDeviceLink/SDLVersion.h4
-rw-r--r--SmartDeviceLink/SDLVersion.m22
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLVersionSpec.m5
4 files changed, 24 insertions, 23 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index 093ee964b..1cfcce89a 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -2634,10 +2634,6 @@
5DADA7771F4E059E0084D17D /* SDLRectangleSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLRectangleSpec.m; sourceTree = "<group>"; };
5DAE06721BDEC6C000F9B498 /* SDLFileSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLFileSpec.m; path = DevAPISpecs/SDLFileSpec.m; sourceTree = "<group>"; };
5DAE06741BDEC6D600F9B498 /* SDLArtworkSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLArtworkSpec.m; path = DevAPISpecs/SDLArtworkSpec.m; sourceTree = "<group>"; };
- 5DB16142202115FC00F310DF /* SDLAsynchronousRPCRequestOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLAsynchronousRPCRequestOperation.h; sourceTree = "<group>"; };
- 5DB16143202115FC00F310DF /* SDLAsynchronousRPCRequestOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLAsynchronousRPCRequestOperation.m; sourceTree = "<group>"; };
- 5DB1616A2022276A00F310DF /* SDLSequentialRPCRequestOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLSequentialRPCRequestOperation.h; sourceTree = "<group>"; };
- 5DB1616B2022276A00F310DF /* SDLSequentialRPCRequestOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLSequentialRPCRequestOperation.m; sourceTree = "<group>"; };
5DB1BCD01D243A8E002FFC37 /* SDLDeleteFileOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLDeleteFileOperationSpec.m; path = DevAPISpecs/SDLDeleteFileOperationSpec.m; sourceTree = "<group>"; };
5DB1BCD11D243A8E002FFC37 /* SDLListFilesOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLListFilesOperationSpec.m; path = DevAPISpecs/SDLListFilesOperationSpec.m; sourceTree = "<group>"; };
5DB1BCD21D243A8E002FFC37 /* SDLUploadFileOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLUploadFileOperationSpec.m; path = DevAPISpecs/SDLUploadFileOperationSpec.m; sourceTree = "<group>"; };
@@ -3381,17 +3377,6 @@
name = Connection;
sourceTree = "<group>";
};
- 5D07C02A2044963400D1ECDC /* Recovered References */ = {
- isa = PBXGroup;
- children = (
- 5DB1616B2022276A00F310DF /* SDLSequentialRPCRequestOperation.m */,
- 5DB16143202115FC00F310DF /* SDLAsynchronousRPCRequestOperation.m */,
- 5DB16142202115FC00F310DF /* SDLAsynchronousRPCRequestOperation.h */,
- 5DB1616A2022276A00F310DF /* SDLSequentialRPCRequestOperation.h */,
- );
- name = "Recovered References";
- sourceTree = "<group>";
- };
5D07C0342044AD1900D1ECDC /* Request Operations */ = {
isa = PBXGroup;
children = (
@@ -3583,7 +3568,6 @@
5D61FA2C1A84237100846EE7 /* SmartDeviceLinkTests */,
5D4346621E6F38E600B639C6 /* SmartDeviceLinkSwift */,
5D4019B01A76EC350006B0C2 /* Products */,
- 5D07C02A2044963400D1ECDC /* Recovered References */,
);
sourceTree = "<group>";
};
diff --git a/SmartDeviceLink/SDLVersion.h b/SmartDeviceLink/SDLVersion.h
index c39714ce5..f7b226206 100644
--- a/SmartDeviceLink/SDLVersion.h
+++ b/SmartDeviceLink/SDLVersion.h
@@ -22,8 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor patch:(NSUInteger)patch;
+ (instancetype)versionWithMajor:(NSUInteger)major minor:(NSUInteger)minor patch:(NSUInteger)patch;
-- (instancetype)initWithString:(NSString *)versionString;
-+ (instancetype)versionWithString:(NSString *)versionString;
+- (nullable instancetype)initWithString:(NSString *)versionString;
++ (nullable instancetype)versionWithString:(NSString *)versionString;
- (instancetype)initWithSyncMsgVersion:(SDLSyncMsgVersion *)syncMsgVersion;
+ (instancetype)versionWithSyncMsgVersion:(SDLSyncMsgVersion *)syncMsgVersion;
diff --git a/SmartDeviceLink/SDLVersion.m b/SmartDeviceLink/SDLVersion.m
index ce29b59f9..21c4d85bb 100644
--- a/SmartDeviceLink/SDLVersion.m
+++ b/SmartDeviceLink/SDLVersion.m
@@ -10,6 +10,8 @@
#import "SDLSyncMsgVersion.h"
+NS_ASSUME_NONNULL_BEGIN
+
@implementation SDLVersion
#pragma mark - Initializers
@@ -29,21 +31,29 @@
return [[self alloc] initWithMajor:major minor:minor patch:patch];
}
-- (instancetype)initWithString:(NSString *)versionString {
+- (nullable instancetype)initWithString:(NSString *)versionString {
self = [super init];
if (!self) { return nil; }
NSArray<NSString *> *splitVersions = [versionString componentsSeparatedByString:@"."];
NSAssert(splitVersions.count == 3, @"Splitting a version string must result in major, minor, and patch. The format must be 'X.X.X'");
+ NSInteger majorInt = splitVersions[0].integerValue;
+ NSInteger minorInt = splitVersions[0].integerValue;
+ NSInteger patchInt = splitVersions[0].integerValue;
+
+ if (majorInt < 0 || minorInt < 0 || patchInt < 0) {
+ NSAssert(NO, @"Attempted to parse invalid SDLVersion: %@", splitVersions);
+ return nil;
+ }
- _major = (NSUInteger)splitVersions[0].integerValue;
- _minor = (NSUInteger)splitVersions[1].integerValue;
- _patch = (NSUInteger)splitVersions[2].integerValue;
+ _major = (NSUInteger)majorInt;
+ _minor = (NSUInteger)minorInt;
+ _patch = (NSUInteger)patchInt;
return self;
}
-+ (instancetype)versionWithString:(NSString *)versionString {
++ (nullable instancetype)versionWithString:(NSString *)versionString {
return [[self alloc] initWithString:versionString];
}
@@ -117,3 +127,5 @@
}
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLVersionSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLVersionSpec.m
index 153039a14..b5dc67dbf 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLVersionSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLVersionSpec.m
@@ -47,6 +47,11 @@ describe(@"a version object", ^{
expect(testVersion.minor).to(equal(minor));
expect(testVersion.patch).to(equal(patch));
});
+
+ fit(@"should fail with negative numbers", ^{
+ testVersion = [[SDLVersion alloc] initWithString:@"-1.-2.-3"];
+ expect(testVersion.major).toNot(equal(major));
+ });
});
context(@"created from a SyncMsgVersion object", ^{