forked from swiftlang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Add a syntactic security check for ObjC NSCoder API.
Method '-[NSCoder decodeValueOfObjCType:at:]' is not only deprecated but also a security hazard, hence a loud check. Differential Revision: https://reviews.llvm.org/D71728
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-ios11.0 -verify=available \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-ios10.0 -verify=notavailable \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple x86_64-apple-macos10.13 -verify=available \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple x86_64-apple-macos10.12 -verify=notavailable \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-watchos4.0 -verify=available \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-watchos3.0 -verify=notavailable \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-tvos11.0 -verify=available \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
// RUN: %clang_analyze_cc1 -triple thumbv7-apple-tvos10.0 -verify=notavailable \ | ||
// RUN: -analyzer-checker=security.insecureAPI.decodeValueOfObjCType %s | ||
|
||
// notavailable-no-diagnostics | ||
|
||
typedef unsigned long NSUInteger; | ||
|
||
@interface NSCoder | ||
- (void)decodeValueOfObjCType:(const char *)type | ||
at:(void *)data; | ||
- (void)decodeValueOfObjCType:(const char *)type | ||
at:(void *)data | ||
size:(NSUInteger)size; | ||
@end | ||
|
||
void test(NSCoder *decoder) { | ||
// This would be a vulnerability on 64-bit platforms | ||
// but not on 32-bit platforms. | ||
NSUInteger x; | ||
[decoder decodeValueOfObjCType:"I" at:&x]; // available-warning{{Deprecated method '-decodeValueOfObjCType:at:' is insecure as it can lead to potential buffer overflows. Use the safer '-decodeValueOfObjCType:at:size:' method}} | ||
[decoder decodeValueOfObjCType:"I" at:&x size:sizeof(x)]; // no-warning | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters