1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-12-04 14:46:31 -05:00

Fix crash when attempting to replace a placeholder with NULL

For example, this solves the combination of an explicit format string
'@a@ - @t@' in combination with an MP3 input file that lacks either
artist or title
This commit is contained in:
Moritz Grimm 2020-04-02 01:09:52 +02:00
parent e00ed8e936
commit 3a791a6de4
3 changed files with 37 additions and 7 deletions

7
NEWS
View File

@ -1,3 +1,10 @@
Changes in 1.0.2, released on XXXX-XX-XX:
* Fix a crash, if metadata placeholders are configured for input files
that do not contain the respective values. From gui-lux on Github (#16).
Changes in 1.0.1, released on 2020-02-22: Changes in 1.0.1, released on 2020-02-22:
* Fix a crash, if there is a typo in the <encoder /> setting * Fix a crash, if there is a typo in the <encoder /> setting

View File

@ -483,15 +483,15 @@ mdata_strformat(struct mdata *md, char *buf, size_t bufsize, const char *format)
memset(dicts, 0, sizeof(dicts)); memset(dicts, 0, sizeof(dicts));
dicts[0].from = PLACEHOLDER_ARTIST; dicts[0].from = PLACEHOLDER_ARTIST;
dicts[0].to = mdata_get_artist(md); dicts[0].to = mdata_get_artist(md) ? mdata_get_artist(md) : "";
dicts[1].from = PLACEHOLDER_ALBUM; dicts[1].from = PLACEHOLDER_ALBUM;
dicts[1].to = mdata_get_album(md); dicts[1].to = mdata_get_album(md) ? mdata_get_album(md) : "";
dicts[2].from = PLACEHOLDER_TITLE; dicts[2].from = PLACEHOLDER_TITLE;
dicts[2].to = mdata_get_title(md); dicts[2].to = mdata_get_title(md) ? mdata_get_title(md) : "";
dicts[3].from = PLACEHOLDER_TRACK; dicts[3].from = PLACEHOLDER_TRACK;
dicts[3].to = mdata_get_filename(md); dicts[3].to = mdata_get_filename(md);
dicts[4].from = PLACEHOLDER_STRING; dicts[4].from = PLACEHOLDER_STRING;
dicts[4].to = mdata_get_songinfo(md); dicts[4].to = mdata_get_songinfo(md) ? mdata_get_songinfo(md) : "";
str = util_expand_words(format, dicts); str = util_expand_words(format, dicts);
ret = (int)strlen(str); ret = (int)strlen(str);

View File

@ -147,15 +147,38 @@ START_TEST(test_mdata_strformat)
int ret; int ret;
ck_assert_int_eq(mdata_parse_file(md, SRCDIR "/test01-artist+album+title.ogg"), 0); ck_assert_int_eq(mdata_parse_file(md, SRCDIR "/test01-artist+album+title.ogg"), 0);
ck_assert_int_lt(mdata_strformat(md, buf, sizeof(buf), NULL), 0);
ret = mdata_strformat(md, buf, sizeof(buf), "@a@/@b@/@t@/@T@/@s@"); ret = mdata_strformat(md, buf, sizeof(buf), "@a@/@b@/@t@/@T@/@s@");
ck_assert_int_eq(ret, (int)strlen(buf)); ck_assert_int_eq(ret, (int)strlen(buf));
ck_assert_str_eq(buf, ck_assert_str_eq(buf,
"test artist/test album/test title" "test artist/test album/test title"
"/" SRCDIR "/test01-artist+album+title.ogg" "/" SRCDIR "/test01-artist+album+title.ogg"
"/test artist - test title - test album"); "/test artist - test title - test album");
ck_assert_int_eq(mdata_parse_file(md, SRCDIR "/test12-artist.ogg"), 0);
ret = mdata_strformat(md, buf, sizeof(buf), "@a@/@b@/@t@/@T@/@s@");
ck_assert_int_eq(ret, (int)strlen(buf));
ck_assert_str_eq(buf,
"test artist//"
"/" SRCDIR "/test12-artist.ogg"
"/test artist");
ck_assert_int_eq(mdata_parse_file(md, SRCDIR "/test15-title.ogg"), 0);
ret = mdata_strformat(md, buf, sizeof(buf), "@a@/@b@/@t@/@T@/@s@");
ck_assert_int_eq(ret, (int)strlen(buf));
ck_assert_str_eq(buf,
"//test title"
"/" SRCDIR "/test15-title.ogg"
"/test title");
ck_assert_int_eq(mdata_parse_file(md, SRCDIR "/test16-nometa.ogg"), 0);
ret = mdata_strformat(md, buf, sizeof(buf), "@a@/@b@/@t@/@T@/@s@");
ck_assert_int_eq(ret, (int)strlen(buf));
ck_assert_str_eq(buf,
"//"
"/" SRCDIR "/test16-nometa.ogg"
"/");
ck_assert_int_lt(mdata_strformat(md, buf, sizeof(buf), NULL), 0);
} }
END_TEST END_TEST