SecItemCopyMatching和Veracode的错误处理



我使用Veracode扫描我的应用程序,并出现关于未选中的错误条件。这是我的代码:

let status = withUnsafeMutablePointer(to: &queryResult) {
SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0))
}
// Check the return status and throw an error if appropriate.
guard status != errSecItemNotFound else {
throw KeychainError.noKeychain
}
guard status == noErr else {
throw KeychainError.unhandledError(status: status)
}

错误在这一行:SecItemCopyMatching(查询为CFDictionary,UnsafeMutablePointer($0((

当应用程序不能正确处理处理过程中发生的错误时,就会出现错误处理问题。如果某个功能没有生成正确的退货/状态代码,或者产品没有处理该功能可能生成的所有退货/状态码,则可能会导致安全问题。类似地,未能捕获函数引发的异常可能会导致程序崩溃或以意外方式运行。

根据withUnsafeMutablePointer的文档,闭包中的参数已经是UnsafeMutablePointer类型的。因此,基本上,您将传递UnsafeMutablePointer<UnsafeMutablePointer>SecItemCopyMatching,其中(如果您想坚持使用UnsafeMutablePointer(应该传递UnsafeMutablePointer<CFTypeRef>。所以试试

SecItemCopyMatching(query as CFDictionary, $0)

最新更新