trailer: handle NULL value when parsing trailer-specific config

When parsing the "key", "command", and "cmd" trailer config, we just make a copy of the value string. If we see an implicit bool like: [trailer "foo"] key we'll segfault trying to copy a NULL pointer. We can fix this with the usual config_error_nonbool() check. I split this out from the other vanilla cases, because at first glance it looks like a better fix here would be to move the NULL check out of the switch statement. But it would change the behavior of other keys like trailer.*.ifExists, where an implicit bool is interpreted as EXISTS_DEFAULT. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 7, 2023 at 02:11 UTC 1b274c98341ef17f3bbfe80f603f629e7c950668
1 file changed +6
trailer.c
+6
@@ -553,16 +553,22 @@ static int git_trailer_config(const char *conf_key, const char *value,
553 case TRAILER_KEY:
554 if (conf->key)
555 warning(_("more than one %s"), conf_key);
556 + if (!value)
557 + return config_error_nonbool(conf_key);
558 conf->key = xstrdup(value);
559 break;
560 case TRAILER_COMMAND:
561 if (conf->command)
562 warning(_("more than one %s"), conf_key);
563 + if (!value)
564 + return config_error_nonbool(conf_key);
565 conf->command = xstrdup(value);
566 break;
567 case TRAILER_CMD:
568 if (conf->cmd)
569 warning(_("more than one %s"), conf_key);
570 + if (!value)
571 + return config_error_nonbool(conf_key);
572 conf->cmd = xstrdup(value);
573 break;
574 case TRAILER_WHERE: