From: Jaroslav Kysela Date: Tue, 15 Mar 2016 15:46:07 +0000 (+0100) Subject: htsmsg: fix crash caused by wrong htsmsg_set_str() update, fixes #3631 X-Git-Tag: v4.2.1~865 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f754e0cd91a6b0d4859cfab9cf99f8aedc11472f;p=thirdparty%2Ftvheadend.git htsmsg: fix crash caused by wrong htsmsg_set_str() update, fixes #3631 --- diff --git a/src/htsmsg.c b/src/htsmsg.c index 844b14b3f..11e36ea36 100644 --- a/src/htsmsg.c +++ b/src/htsmsg.c @@ -417,6 +417,20 @@ htsmsg_field_set_str(htsmsg_field_t *f, const char *str) return 0; } +/* + * + */ +int +htsmsg_field_set_str_force(htsmsg_field_t *f, const char *str) +{ + if (f->hmf_type != HMF_STR) { + htsmsg_field_data_destroy(f); + f->hmf_type = HMF_STR; + f->hmf_str = ""; + } + return htsmsg_field_set_str(f, str); +} + /* * */ @@ -781,15 +795,15 @@ htsmsg_field_get_string(htsmsg_field_t *f) case HMF_STR: break; case HMF_BOOL: - htsmsg_field_set_str(f, f->hmf_bool ? "true" : "false"); + htsmsg_field_set_str_force(f, f->hmf_bool ? "true" : "false"); break; case HMF_S64: snprintf(buf, sizeof(buf), "%"PRId64, f->hmf_s64); - htsmsg_field_set_str(f, buf); + htsmsg_field_set_str_force(f, buf); break; case HMF_DBL: snprintf(buf, sizeof(buf), "%lf", f->hmf_dbl); - htsmsg_field_set_str(f, buf); + htsmsg_field_set_str_force(f, buf); break; } return f->hmf_str; diff --git a/src/htsmsg.h b/src/htsmsg.h index 0f8996307..b278cbe3a 100644 --- a/src/htsmsg.h +++ b/src/htsmsg.h @@ -183,6 +183,7 @@ int htsmsg_set_str(htsmsg_t *msg, const char *name, const char *str); * Update a string field */ int htsmsg_field_set_str(htsmsg_field_t *f, const char *str); +int htsmsg_field_set_str_force(htsmsg_field_t *f, const char *str); /** * Add an field where source is a list or map message.