From 24e1a5ebaf4455386a53bcdc5bc3d01a834b5fc7 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 12 May 2023 00:46:35 -0700 Subject: [PATCH] pipe-loader: avoid undefined memcpy behavior If either dest or src is an invalid or null pointer, the behavior is undefined, even if count is zero. Cc: mesa-stable Signed-off-by: Yiwei Zhang Reviewed-by: Mike Blumenkrantz Part-of: (cherry picked from commit 5b31039033114bb8e0de25b87119e8d97186bced) --- .pick_status.json | 2 +- src/gallium/auxiliary/pipe-loader/pipe_loader.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e8ac127a920..82cf9489ec4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3883,7 +3883,7 @@ "description": "pipe-loader: avoid undefined memcpy behavior", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c index 1c58eaefd04..5b69599ee4f 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c @@ -97,8 +97,12 @@ merge_driconf(const driOptionDescription *driver_driconf, unsigned driver_count, return NULL; } - memcpy(merged, gallium_driconf, sizeof(*merged) * gallium_count); - memcpy(&merged[gallium_count], driver_driconf, sizeof(*merged) * driver_count); + if (gallium_count) + memcpy(merged, gallium_driconf, sizeof(*merged) * gallium_count); + if (driver_count) { + memcpy(&merged[gallium_count], driver_driconf, + sizeof(*merged) * driver_count); + } *merged_count = driver_count + gallium_count; return merged;