player/command: don't return ill-formed node if there is no default val

option-info/<name>/default-value would be initialized with zeroed
object, which is not valid for string typed options, as the would be set
to NULL.

Found by OSS-Fuzz.
This commit is contained in:
Kacper Michajłow 2024-07-16 22:39:12 +02:00
parent 3cc42083aa
commit 607ad8943b
2 changed files with 5 additions and 2 deletions

View File

@ -255,6 +255,8 @@ static const char special_escape[] = {
static void write_json_str(bstr *b, unsigned char *str) static void write_json_str(bstr *b, unsigned char *str)
{ {
assert(str);
APPEND(b, "\""); APPEND(b, "\"");
while (1) { while (1) {
unsigned char *cur = str; unsigned char *cur = str;

View File

@ -3605,7 +3605,8 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
union m_option_value def = m_option_value_default; union m_option_value def = m_option_value_default;
const void *def_ptr = m_config_get_co_default(mpctx->mconfig, co); const void *def_ptr = m_config_get_co_default(mpctx->mconfig, co);
if (def_ptr && opt->type->size > 0) bool has_default = def_ptr && opt->type->size > 0;
if (has_default)
memcpy(&def, def_ptr, opt->type->size); memcpy(&def, def_ptr, opt->type->size);
bool has_minmax = opt->min < opt->max && bool has_minmax = opt->min < opt->max &&
@ -3643,7 +3644,7 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
{"set-from-commandline", SUB_PROP_BOOL(co->is_set_from_cmdline)}, {"set-from-commandline", SUB_PROP_BOOL(co->is_set_from_cmdline)},
{"set-locally", SUB_PROP_BOOL(co->is_set_locally)}, {"set-locally", SUB_PROP_BOOL(co->is_set_locally)},
{"expects-file", SUB_PROP_BOOL(opt->flags & M_OPT_FILE)}, {"expects-file", SUB_PROP_BOOL(opt->flags & M_OPT_FILE)},
{"default-value", *opt, def}, {"default-value", *opt, def, .unavailable = !has_default},
{"min", SUB_PROP_DOUBLE(opt->min), {"min", SUB_PROP_DOUBLE(opt->min),
.unavailable = !(has_minmax && opt->min != DBL_MIN)}, .unavailable = !(has_minmax && opt->min != DBL_MIN)},
{"max", SUB_PROP_DOUBLE(opt->max), {"max", SUB_PROP_DOUBLE(opt->max),