diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/journal/catalog.c | 4 | ||||
-rw-r--r-- | src/journal/test-catalog.c | 12 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c index 2be81aa2f7..e3a3354ab7 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -150,10 +150,10 @@ int catalog_file_lang(const char* filename, char **lang) { return 0; beg = end - 1; - while (beg > filename && *beg != '.') + while (beg > filename && *beg != '.' && *beg != '/' && end - beg < 32) beg --; - if (beg <= filename || end <= beg + 1 || end - beg > 32) + if (*beg != '.' || end <= beg + 1) return 0; _lang = strndup(beg + 1, end - beg - 1); diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index 863b9f4b51..ffe180265b 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -121,7 +121,7 @@ static void test_catalog_update(void) { } static void test_catalog_file_lang(void) { - _cleanup_free_ char *lang = NULL, *lang2 = NULL, *lang3 = NULL; + _cleanup_free_ char *lang = NULL, *lang2 = NULL, *lang3 = NULL, *lang4 = NULL; assert_se(catalog_file_lang("systemd.de_DE.catalog", &lang) == 1); assert_se(streq(lang, "de_DE")); @@ -140,6 +140,12 @@ static void test_catalog_file_lang(void) { assert_se(catalog_file_lang("systemd.0123456789012345678901234567890.catalog", &lang3) == 1); assert_se(streq(lang3, "0123456789012345678901234567890")); + + assert_se(catalog_file_lang("/x/y/systemd.catalog", &lang4) == 0); + assert_se(lang4 == NULL); + + assert_se(catalog_file_lang("/x/y/systemd.ru_RU.catalog", &lang4) == 1); + assert_se(streq(lang4, "ru_RU")); } int main(int argc, char *argv[]) { @@ -150,6 +156,8 @@ int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); + test_catalog_file_lang(); + test_catalog_importing(); test_catalog_update(); @@ -166,7 +174,5 @@ int main(int argc, char *argv[]) { if (database) unlink(database); - test_catalog_file_lang(); - return 0; } |