Skip to content

Undefined behaviour in loadDefaults in FIRCLSUserDefaults.m #5454

Closed
@C0lumbo

Description

@C0lumbo

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 11.2.1
  • Firebase SDK version: 6.22.0
  • Firebase Component: Crashlytics
  • Component version: 6.22.0
  • Installation method: CocoaPods

[REQUIRED] Step 2: Describe the problem

Running on iOS with UBSan enabled (https://developer.apple.com/documentation/code_diagnostics/undefined_behavior_sanitizer/enabling_the_undefined_behavior_sanitizer?language=objc) I hit a piece of undefined behaviour in Crashlytics which causes UBSan to break into the debugger with an "Invalid Boolean" error.

I believe it's likely to be harmless, but also think it should be fixed to reduce noise, and technically the results of undefined behaviour are somewhat unlimited.

Steps to reproduce:

Enable UBSan (https://developer.apple.com/documentation/code_diagnostics/undefined_behavior_sanitizer/enabling_the_undefined_behavior_sanitizer?language=objc)
Run a project with Crashlytics for the first time.

Observe that UBSan breaks due to an invalid value for isDirectory in loadDefaults. This is because isDirectory is not initialized when it's declared, nor is it initialised during the call to fileExistsAtPath (https://developer.apple.com/documentation/foundation/nsfilemanager/1410277-fileexistsatpath?language=objc) because "If path doesn’t exist, this value is undefined upon return. "

The simplest fix would be to remove isDirectory from the "else if (!fileExists && !isDirectory)" condition changing it to "else if (!fileExists) "

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions