validate-utils: Only modify structure fields that really need updates

This avoids memory corruption in users of that structure which
were (rightfullly) assuming static fields (such as name) wouldn't
change. Without this, they would be using strings which will have been freed in
the meantime.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/252>
This commit is contained in:
Edward Hervey 2021-08-20 09:22:28 +02:00 committed by Edward Hervey
parent cdfa0778c7
commit 1e1e9f2197

View file

@ -1339,8 +1339,6 @@ done:
static gboolean
_structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
{
gchar *str;
if (field_id == filename_quark || field_id == debug_quark
|| field_id == debug_quark)
return TRUE;
@ -1358,12 +1356,18 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
if (!G_VALUE_HOLDS_STRING (value))
return TRUE;
str =
gst_validate_replace_variables_in_string (data->source, data->local_vars,
g_value_get_string (value), data->flags);
if (str) {
g_value_set_string (value, str);
g_free (str);
if (!_variables_regex)
_variables_regex = g_regex_new ("\\$\\((\\w+)\\)", 0, 0, NULL);
/* Don't replace string contents unless really needed */
if (g_regex_match (_variables_regex, g_value_get_string (value), 0, NULL)) {
gchar *str = gst_validate_replace_variables_in_string (data->source,
data->local_vars,
g_value_get_string (value), data->flags);
if (str) {
g_value_set_string (value, str);
g_free (str);
}
}
if (!(data->flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION))