Skip to content

Commit 0a2b1bf

Browse files
committed
add length checks to format::Info array params
1 parent 4c12cd1 commit 0a2b1bf

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pulse-binding/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Dropped deprecated `CardProfileInfo2` introspection alias.
99
* Added `set_corked_state()` method to `Stream` providing an alternative to using `cork()` and
1010
`uncork()`.
11+
* Added length checks to the `set_prop_int_array()` and `set_prop_string_array()` methods of
12+
`format::Info`. Now should you happen to pass in an array with a length larger than can fit
13+
within the `len` parameter of the C function, it will panic.
1114

1215
# 2.29.0 (March 3rd, 2025)
1316

pulse-binding/src/format.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ impl Info {
497497
}
498498

499499
/// Sets a property with a list of integer values.
500+
///
501+
/// Panics if length of array is larger than `i32::MAX`.
500502
pub fn set_prop_int_array(&mut self, key: &str, values: &[i32]) {
503+
assert!(values.len() <= i32::MAX as u32);
501504
// Warning: New CStrings will be immediately freed if not bound to a variable, leading to
502505
// as_ptr() giving dangling pointers!
503506
let c_key = CString::new(key).unwrap();
@@ -525,7 +528,10 @@ impl Info {
525528
}
526529

527530
/// Sets a property with a list of string values.
531+
///
532+
/// Panics if length of array is larger than `i32::MAX`.
528533
pub fn set_prop_string_array(&mut self, key: &str, values: &[&str]) {
534+
assert!(values.len() <= i32::MAX as u32);
529535
// Warning: New CStrings will be immediately freed if not bound to a variable, leading to
530536
// as_ptr() giving dangling pointers!
531537
let c_key = CString::new(key).unwrap();

0 commit comments

Comments
 (0)