From 469fcf67077516bb68852640776759121f0e61c9 Mon Sep 17 00:00:00 2001 From: Marek Skrobacki Date: Sat, 12 Aug 2023 22:57:28 +0100 Subject: [PATCH] [mpd] Sanitize newline characters in ID3 tag values (#1615) Fixes https://github.com/owntone/owntone-server/issues/1613 --- src/mpd.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/mpd.c b/src/mpd.c index 289d6a16..49b83af3 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -2721,6 +2721,27 @@ mpd_command_findadd(struct evbuffer *evbuf, int argc, char **argv, char **errmsg return 0; } +/* + * Some MPD clients crash if the tag value includes the newline character. + * While they should normally not be included in most ID3 tags, they sometimes + * are, so we just change them to space. See #1613 for more details. + */ + +static void +sanitize_value(char **strval) +{ + char *ptr = *strval; + + while(*ptr != '\0') + { + if(*ptr == '\n') + { + *ptr = ' '; + } + ptr++; + } +} + static int mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx) { @@ -2784,6 +2805,7 @@ mpd_command_list(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, s if (!(*strval) || (**strval == '\0')) continue; + sanitize_value(strval); evbuffer_add_printf(evbuf, "%s: %s\n", tagtype->tag,