From 9770ce6c44cd26e7b9e5b525c3222281d32dcb6f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 2 Sep 2016 19:00:34 +0200 Subject: m_config: make sure profile values are never NULL Apparently this was supposed to be handled - but badly at best. Make unset values always have the value "" instead of NULL to avoid special-cases. In particular, this fixes passing NULL to a %s format specifier to printf in show_profile(). Glibc prints this as "(null)", but it's undefined behavior, and other libcs can crash. --- options/m_config.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 125702c362..f3bbe7d8c9 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -943,7 +943,7 @@ struct m_profile *m_config_add_profile(struct m_config *config, char *name) void m_profile_set_desc(struct m_profile *p, bstr desc) { talloc_free(p->desc); - p->desc = bstrdup0(p, desc); + p->desc = bstrto0(p, desc); } int m_config_set_profile_option(struct m_config *config, struct m_profile *p, @@ -955,8 +955,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, if (i < 0) return i; p->opts = talloc_realloc(p, p->opts, char *, 2 * (p->num_opts + 2)); - p->opts[p->num_opts * 2] = bstrdup0(p, name); - p->opts[p->num_opts * 2 + 1] = bstrdup0(p, val); + p->opts[p->num_opts * 2] = bstrto0(p, name); + p->opts[p->num_opts * 2 + 1] = bstrto0(p, val); p->num_opts++; p->opts[p->num_opts * 2] = p->opts[p->num_opts * 2 + 1] = NULL; return 1; @@ -1005,8 +1005,7 @@ struct mpv_node m_config_get_profiles(struct m_config *config) for (int n = 0; n < profile->num_opts; n++) { struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP); node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]); - if (profile->opts[n * 2 + 1]) - node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); + node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); } } -- cgit v1.2.3