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 <zzyiwei@chromium.org>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22979>
(cherry picked from commit 5b31039033)
This commit is contained in:
Yiwei Zhang 2023-05-12 00:46:35 -07:00 committed by Eric Engestrom
parent 1fa4d3af65
commit 24e1a5ebaf
2 changed files with 7 additions and 3 deletions

View file

@ -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
},

View file

@ -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;