From: Razvan Cojocaru <[email protected]> The text following the last occurrence of the search string was never copied, so a name/value like "[email protected]" was answered with the bare username.
Copy the rest of the string after the loop and add a test for it. Change-Id: I9b0ea680539846b287d5a5b77f981437f7dc7835 Signed-off-by: Razvan Cojocaru <[email protected]> Acked-by: Frank Lichtenheld <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2374 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2374 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld <[email protected]> diff --git a/src/plugins/auth-pam/utils.c b/src/plugins/auth-pam/utils.c index 01cc4de..22c4eea 100644 --- a/src/plugins/auth-pam/utils.c +++ b/src/plugins/auth-pam/utils.c @@ -88,6 +88,7 @@ searching = scratch + searchforlen; scratch = strstr(searching, searchfor); } + memcpy(target, searching, strlen(searching)); return strdup(temp); } diff --git a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c index 89f0642..cee8ebc 100644 --- a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c +++ b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c @@ -64,6 +64,17 @@ } static void +replace_with_trailing_text__trailing_text_is_kept(void **state) +{ + char *replaced = searchandreplace("aXbXcd", "X", "YY"); + + assert_non_null(replaced); + assert_string_equal("aYYbYYcd", replaced); + + free(replaced); +} + +static void pattern_not_found__returns_original(void **state) { char *replaced = searchandreplace("abc", "X", "Y"); @@ -84,6 +95,7 @@ cmocka_unit_test(replace_single_char__one_time__match_is_replaced), cmocka_unit_test(replace_single_char__multiple_times__match_all_matches_are_replaced), cmocka_unit_test(replace_longer_text__multiple_times__match_all_matches_are_replaced), + cmocka_unit_test(replace_with_trailing_text__trailing_text_is_kept), cmocka_unit_test(pattern_not_found__returns_original), }; _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
