Fix segfault in expand_alternative_phrase_option

string_tree_get_alternative can return NULL
This commit is contained in:
Gregory Oschwald
2018-01-02 13:28:51 -08:00
parent 18cc0e37e6
commit 2f6749fe03
2 changed files with 16 additions and 2 deletions

View File

@@ -1491,8 +1491,12 @@ void expand_alternative_phrase_option(cstring_array *strings, khash_t(str_set) *
for (; !string_tree_iterator_done(iter); string_tree_iterator_next(iter)) {
char_array_clear(temp_string);
string_tree_iterator_foreach_token(iter, token, {
if (token == NULL) {
log_debug("token=NULL\n");
} else {
log_debug("token=%s\n", token);
char_array_append(temp_string, token);
}
})
char_array_terminate(temp_string);

View File

@@ -135,6 +135,15 @@ TEST test_expansions(void) {
CHECK_CALL(test_expansion_contains_with_languages("Marktstrasse", "markt strasse", options, 1, "de"));
CHECK_CALL(test_expansion_contains_with_languages("Hoofdstraat", "hoofdstraat", options, 1, "nl"));
CHECK_CALL(test_expansion_contains_with_languages("มงแตร", "มงแตร", options, 1, "th"));
PASS();
}
TEST test_expansion_for_invalid_input(void) {
size_t num_expansions;
// This is tested as the input caused a segfault in expand_alternative_phrase_option
libpostal_expand_address("bob-ad1233@blah.co", libpostal_get_default_options(), &num_expansions);
PASS();
}
@@ -314,6 +323,7 @@ SUITE(libpostal_expansion_tests) {
RUN_TEST(test_po_box_root_expansions);
RUN_TEST(test_expansions_language_classifier);
RUN_TEST(test_expansions_no_options);
RUN_TEST(test_expansion_for_invalid_input);
libpostal_teardown();
libpostal_teardown_language_classifier();