Fix passed parameter to system catalog

The PR #6624 introduces a catalog access to get the Oid of a relation.
However, C strings were passed to the catalog cache and NameStr are
needed since namehashfast() is called internally. This PR fixes the
problem. Found by sanitizer.
This commit is contained in:
Jan Nidzwetzki 2024-02-16 19:53:28 +01:00 committed by Jan Nidzwetzki
parent 1f217ed1be
commit 7d6332e83a

View File

@ -342,15 +342,23 @@ get_direct_view_oid(int32 mat_hypertable_id)
bool is_null = false;
/* We use the view_schema and view_name to get data from the system catalog. Even char pointers
* are passed to the catalog, it calls namehashfast() internally, which assumes that a char of
* NAMEDATALEN is allocated. */
NameData view_schema_name;
NameData view_name_name;
char *view_schema =
DatumGetCString(slot_getattr(slot, Anum_continuous_agg_direct_view_schema, &is_null));
Ensure(!is_null, "unable to get view schema for oid %d", mat_hypertable_id);
Assert(view_schema != NULL);
namestrcpy(&view_schema_name, view_schema);
char *view_name =
DatumGetCString(slot_getattr(slot, Anum_continuous_agg_direct_view_name, &is_null));
Ensure(!is_null, "unable to get view name for oid %d", mat_hypertable_id);
Assert(view_name != NULL);
namestrcpy(&view_name_name, view_name);
got_next_slot = index_getnext_slot(indexscan, ForwardScanDirection, slot);
Ensure(!got_next_slot, "found duplicate definitions for CAgg mat_ht %d", mat_hypertable_id);
@ -362,7 +370,8 @@ get_direct_view_oid(int32 mat_hypertable_id)
relation_close(cagg_idx_rel, AccessShareLock);
/* Get Oid of user view */
Oid direct_view_oid = ts_get_relation_relid(view_schema, view_name, false);
Oid direct_view_oid =
ts_get_relation_relid(NameStr(view_schema_name), NameStr(view_name_name), false);
Assert(OidIsValid(direct_view_oid));
return direct_view_oid;
}