Skip to content

Commit cd5746d

Browse files
committed
fix buffer overrun issue (#470) where initialization with random bytes ignored the passed length and used a fixed length of 32 bytes. This results in only the first 32 bytes of larger objects being initialized, and overruns beyond the end for smaller objects.
1 parent 5b45521 commit cd5746d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Sources/web3swift/Convenience/Data+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public extension Data {
6565
let result = data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) -> Int32? in
6666
if let bodyAddress = body.baseAddress, body.count > 0 {
6767
let pointer = bodyAddress.assumingMemoryBound(to: UInt8.self)
68-
return SecRandomCopyBytes(kSecRandomDefault, 32, pointer)
68+
return SecRandomCopyBytes(kSecRandomDefault, length, pointer)
6969
} else {
7070
return nil
7171
}

Sources/web3swift/Convenience/SECP256k1.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ extension SECP256K1 {
343343
let result = data.withUnsafeMutableBytes { (mutableRBBytes) -> Int32? in
344344
if let mutableRBytes = mutableRBBytes.baseAddress, mutableRBBytes.count > 0 {
345345
let mutableBytes = mutableRBytes.assumingMemoryBound(to: UInt8.self)
346-
return SecRandomCopyBytes(kSecRandomDefault, 32, mutableBytes)
346+
return SecRandomCopyBytes(kSecRandomDefault, length, mutableBytes)
347347
} else {
348348
return nil
349349
}

Sources/web3swift/KeystoreManager/EthereumKeystoreV3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class EthereumKeystoreV3: AbstractKeystore {
9696
if (keyData == nil) {
9797
throw AbstractKeystoreError.encryptionError("Encryption without key data")
9898
}
99-
let saltLen = 32;
99+
let saltLen = 32
100100
guard let saltData = Data.randomBytes(length: saltLen) else {
101101
throw AbstractKeystoreError.noEntropyError
102102
}

0 commit comments

Comments
 (0)