nir: fix use-after-free on function parameter names

Fixes: 3da8444be5 ("nir: add names to function parameters")
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35098>
(cherry picked from commit bc444f6d26)
This commit is contained in:
Karol Herbst 2025-05-21 23:09:44 +02:00 committed by Eric Engestrom
parent f1672e0be2
commit b456049782
4 changed files with 9 additions and 3 deletions

View file

@ -2174,7 +2174,7 @@
"description": "nir: fix use-after-free on function parameter names",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "3da8444be563a150fff6dd686dd68febf4cf76c9",
"notes": null

View file

@ -2053,8 +2053,10 @@ read_function(read_ctx *ctx)
for (unsigned i = 0; i < fxn->num_params; i++) {
uint32_t val = blob_read_uint32(ctx->blob);
bool has_name = (val & 0x10000);
if (has_name)
fxn->params[i].name = blob_read_string(ctx->blob);
if (has_name) {
char *name = blob_read_string(ctx->blob);
fxn->params[i].name = ralloc_strdup(ctx->nir, name);
}
fxn->params[i].num_components = val & 0xff;
fxn->params[i].bit_size = (val >> 8) & 0xff;

View file

@ -133,6 +133,9 @@ sweep_function(nir_shader *nir, nir_function *f)
ralloc_steal(nir, f);
ralloc_steal(nir, f->params);
for (unsigned i = 0; i < f->num_params; i++)
ralloc_steal(nir, (char *)f->params[i].name);
if (f->impl)
sweep_impl(nir, f->impl);
}

View file

@ -154,6 +154,7 @@ static nir_function *mangle_and_find(struct vtn_builder *b,
decl->params = ralloc_array(b->shader, nir_parameter, decl->num_params);
for (unsigned i = 0; i < decl->num_params; i++) {
decl->params[i] = found->params[i];
decl->params[i].name = ralloc_strdup(b->shader, found->params[i].name);
}
found = decl;
}