Skip to content

Commit c55993d

Browse files
authored
Prevent crashing when calling quotactl with UIDs greater than Int32.max (#1146)
* Prevent crashing when calling quotactl with UIDs greater than Int32.max * Add comment
1 parent e66da69 commit c55993d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/FoundationEssentials/FileManager/FileManager+Files.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,9 @@ extension _FileManagerImpl {
718718
func _quotactl<T>(_ path: UnsafePointer<CChar>, _ cmd: Int32, _ type: Int32, _ uid: uid_t, init: T) -> T? {
719719
var res = `init`
720720
let success = withUnsafeMutableBytes(of: &res) { buffer in
721-
quotactl(path, QCMD(cmd, type), Int32(uid), buffer.baseAddress!) == 0
721+
// quotactl's parameter is annotated as `int` (signed 32bit) instead of `uid_t` (unsigned 32bit)
722+
// UIDs greater than Int32.max are valid so we perform a bit-pattern cast here to prevent crashing on such values
723+
quotactl(path, QCMD(cmd, type), Int32(bitPattern: uid), buffer.baseAddress!) == 0
722724
}
723725
return success ? res : nil
724726
}

0 commit comments

Comments
 (0)