Skip to content

Commit

Permalink
Fixed potential crash bug in [FSUtils mountedFileSystems] (stack over…
Browse files Browse the repository at this point in the history
…flow bug) #25
  • Loading branch information
sveinbjornt committed Sep 19, 2023
1 parent bb64d78 commit 9f74d34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 0 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
* Always (re)select "General" tab when Preferences are shown
* Show Path Control w. selected path at bottom of table view when item selected

# TODO for Sloth 3.1

* Disable filtering by file system since it could cause a crash after kernel API changes in macOS 13
2 changes: 1 addition & 1 deletion resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>313</string>
<string>320</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
18 changes: 10 additions & 8 deletions source/Util/FSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@
#import <sys/param.h>
#import <sys/mount.h>

#define MAX_FILESYSTEMS 1024
#define MAX_FILESYSTEMS 128

@implementation FSUtils

+ (NSDictionary *)mountedFileSystems {
struct statfs buf[MAX_FILESYSTEMS];

int fs_count = getfsstat(NULL, 0, MNT_NOWAIT);
if (fs_count == -1) {
fprintf(stderr, "Error: %d\n", errno);
return nil;
return @{};
}
if (fs_count > MAX_FILESYSTEMS) {
fprintf(stderr, "Too many filesystems, bailing");
return @{};
}

getfsstat(buf, fs_count * sizeof(statfs), MNT_NOWAIT);

struct statfs buf[fs_count];
getfsstat(buf, fs_count * sizeof(buf[0]), MNT_NOWAIT);

NSMutableDictionary *fsdict = [NSMutableDictionary dictionary];

Expand All @@ -64,9 +68,7 @@ + (NSDictionary *)mountedFileSystems {
};
}

DLog(@"File system info: %@", fsdict);

return [fsdict copy]; // Return immutable copy
return [fsdict copy];
}

@end

0 comments on commit 9f74d34

Please sign in to comment.