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>
This commit is contained in:
Karol Herbst
2025-05-21 23:09:44 +02:00
committed by Marge Bot
parent 31cf6b94ad
commit bc444f6d26
3 changed files with 8 additions and 2 deletions
+4 -2
View File
@@ -2060,8 +2060,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;
+3
View File
@@ -140,6 +140,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);
}
+1
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;
}