From fb663417c7e2c7a6d2ccd77ea7f30f902536ab17 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 29 Jul 2024 14:40:08 +0200 Subject: [PATCH] rusticl/program: protect against 0 length in slice::from_raw_parts Fixes: e028baa1772 ("rusticl/program: implement clCreateProgramWithBinary") Part-of: (cherry picked from commit ad6fb3406b500be4a78ef87f554fffcecff057dc) --- .pick_status.json | 2 +- src/gallium/frontends/rusticl/api/program.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 6331166a953..d2fe0f58076 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -144,7 +144,7 @@ "description": "rusticl/program: protect against 0 length in slice::from_raw_parts", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e028baa1772eeaa55393b1d01d5e5fb217474f95", "notes": null diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index 7cd64c24a9c..577cbf6b893 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -183,14 +183,16 @@ fn create_program_with_binary( ) -> CLResult { let c = Context::arc_from_raw(context)?; let devs = Device::refs_from_arr(device_list, num_devices)?; - let mut binary_status = - unsafe { cl_slice::from_raw_parts_mut(binary_status, num_devices as usize) }.ok(); // CL_INVALID_VALUE if device_list is NULL or num_devices is zero. if devs.is_empty() { return Err(CL_INVALID_VALUE); } + // needs to happen after `devs.is_empty` check to protect against num_devices being 0 + let mut binary_status = + unsafe { cl_slice::from_raw_parts_mut(binary_status, num_devices as usize) }.ok(); + // CL_INVALID_VALUE if lengths or binaries is NULL if lengths.is_null() || binaries.is_null() { return Err(CL_INVALID_VALUE);