[Openvpn-devel,v1] auth-pam: keep the text after the last match in searchandreplace()
Commit Message
From: Razvan Cojocaru <razvanc@mailbox.org>
The text following the last occurrence of the search string was never
copied, so a name/value like "USERNAME@example.com" 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 <razvanc@mailbox.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
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 <frank@lichtenheld.com>
@@ -88,6 +88,7 @@
searching = scratch + searchforlen;
scratch = strstr(searching, searchfor);
}
+ memcpy(target, searching, strlen(searching));
return strdup(temp);
}
@@ -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),
};