Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when opening VM Configuration with a removable drive present #2284

Closed
conath opened this issue Jan 24, 2021 · 1 comment · Fixed by #2285
Closed

Crash when opening VM Configuration with a removable drive present #2284

conath opened this issue Jan 24, 2021 · 1 comment · Fixed by #2285

Comments

@conath
Copy link
Contributor

conath commented Jan 24, 2021

Steps to reproduce

  1. Create a UTM VM with a removable drive and a non-removable drive
  2. Open the VM's configuration

Location and reason of crash
While checking for "orphaned" drive images on the file system, the new orphanedDrives method tries to get the driveImagePathForIndex for all drives (UTMConfiguration+Drives.m line 75), even though this path isn't set for removable drives (their file reference is stored in the ViewState as bookmark).

Technical cause of crash
The result of driveImagePathForIndex is added to an NSMutableSet, which can't handle nil values. This causes a crash in [__NSSetM addObject:]: because object cannot be nil.

Solution
There are two solutions:

  1. Check if the result of driveImagePathForIndex is nil and don't add it in that case.
  2. Check if the drive at i is removable (driveRemovableForIndex) and don't add it in that case.

Since a non-removable drive by definition always has an image path, I believe solution 2 should be implemented.

@conath
Copy link
Contributor Author

conath commented Jan 24, 2021

I have verified that solution 2 prevents the crash. I have also discovered that there is a certain circumstance in which a removable drive will have the path @"" (empty string) set in the configuration instead of nil, leading to no crash despite the steps to reproduce. (see below)

The empty string comes from creating a new drive, which results in an empty string passed and saved as path that is retained if the drive is later changed to be removable (this is currently impossible in the UI but was possible in a previous version).

The empty string in the removable drive configuration is also set in legacy UI saveButtonPressed, if a previously existing removable drive is edited and saved. VMConfigDriveDetailViewController.m line 172

I suggest changing the implementation of setDriveRemovable to be consistent with the rest of the removable drive implementation. This means to remove the image path instead of setting it to an empty string.

conath added a commit to conath/UTM that referenced this issue Jan 24, 2021
@osy osy closed this as completed in #2285 Jan 24, 2021
osy added a commit that referenced this issue Jan 24, 2021
Fix crash when opening VM configuration #2284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant