Commit 3a791a6d authored by Moritz Grimm's avatar Moritz Grimm
Browse files

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
parent e00ed8e9
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:
* Fix a crash, if there is a typo in the <encoder /> setting
......
......@@ -483,15 +483,15 @@ mdata_strformat(struct mdata *md, char *buf, size_t bufsize, const char *format)
memset(dicts, 0, sizeof(dicts));
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].to = mdata_get_album(md);
dicts[1].to = mdata_get_album(md) ? mdata_get_album(md) : "";
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].to = mdata_get_filename(md);
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);
ret = (int)strlen(str);
......
......@@ -147,15 +147,38 @@ START_TEST(test_mdata_strformat)
int ret;
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@");
ck_assert_int_eq(ret, (int)strlen(buf));
ck_assert_str_eq(buf,
"test artist/test album/test title"
"/" SRCDIR "/test01-artist+album+title.ogg"
"/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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment