Skip to content

Commit 707c8ef

Browse files
committed
uefi: memory safety fixes (UB!)
1 parent b02a37d commit 707c8ef

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

uefi-test-runner/examples/sierpinski.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ impl Buffer {
4848
}
4949

5050
/// Blit the buffer to the framebuffer.
51-
fn blit(&self, gop: &mut GraphicsOutput) -> Result {
51+
fn blit(&mut self, gop: &mut GraphicsOutput) -> Result {
5252
gop.blt(BltOp::BufferToVideo {
53-
buffer: &self.pixels,
53+
buffer: &mut self.pixels,
5454
src: BltRegion::Full,
5555
dest: (0, 0),
5656
dims: (self.width, self.height),
@@ -59,12 +59,12 @@ impl Buffer {
5959

6060
/// Update only a pixel to the framebuffer.
6161
fn blit_pixel(
62-
&self,
62+
&mut self,
6363
gop: &mut GraphicsOutput,
6464
coords: (usize, usize),
6565
) -> Result {
6666
gop.blt(BltOp::BufferToVideo {
67-
buffer: &self.pixels,
67+
buffer: &mut self.pixels,
6868
src: BltRegion::SubRectangle {
6969
coords,
7070
px_stride: self.width,

uefi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
image in QEMU or Cloud Hypervisor, when the debugcon/debug-console device is
2424
available.
2525
- The documentation for UEFI protocols has been streamlined and improved.
26+
- Fixed memory safety bug in `SimpleNetwork::read_nv_data`. The `buffer`
27+
parameter is now mutable.
28+
- Fixed memory safety bug in `GraphicsOutput::blt`
2629

2730
# uefi - 0.35.0 (2025-05-04)
2831

uefi/src/proto/console/gop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl GraphicsOutput {
201201
match src_region {
202202
BltRegion::Full => (self.0.blt)(
203203
&mut self.0,
204-
buffer.as_ptr() as *mut _,
204+
buffer.as_mut_ptr().cast(),
205205
GraphicsOutputBltOperation::BLT_BUFFER_TO_VIDEO,
206206
0,
207207
0,
@@ -217,7 +217,7 @@ impl GraphicsOutput {
217217
px_stride,
218218
} => (self.0.blt)(
219219
&mut self.0,
220-
buffer.as_ptr() as *mut _,
220+
buffer.as_mut_ptr().cast(),
221221
GraphicsOutputBltOperation::BLT_BUFFER_TO_VIDEO,
222222
src_x,
223223
src_y,
@@ -533,7 +533,7 @@ pub enum BltOp<'buf> {
533533
/// Delta must be the stride (count of bytes in a row) of the buffer.
534534
BufferToVideo {
535535
/// Buffer from which to copy data.
536-
buffer: &'buf [BltPixel],
536+
buffer: &'buf mut [BltPixel],
537537
/// Location of the source rectangle in the user-provided buffer.
538538
src: BltRegion,
539539
/// Coordinates of the destination rectangle, in the frame buffer.

uefi/src/proto/network/snp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ impl SimpleNetwork {
144144

145145
/// Perform read operations on the NVRAM device attached to
146146
/// a network interface.
147-
pub fn read_nv_data(&self, offset: usize, buffer: &[u8]) -> Result {
147+
pub fn read_nv_data(&self, offset: usize, buffer: &mut [u8]) -> Result {
148148
unsafe {
149149
(self.0.non_volatile_data)(
150150
&self.0,
151151
Boolean::from(true),
152152
offset,
153153
buffer.len(),
154-
buffer.as_ptr() as *mut c_void,
154+
buffer.as_mut_ptr().cast(),
155155
)
156156
}
157157
.to_result()

0 commit comments

Comments
 (0)