Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2374?usp=email

to review the following change.


Change subject: auth-pam: keep the text after the last match in 
searchandreplace()
......................................................................

auth-pam: keep the text after the last match in searchandreplace()

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]>
---
M src/plugins/auth-pam/utils.c
M tests/unit_tests/plugins/auth-pam/test_search_and_replace.c
2 files changed, 13 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/74/2374/1

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),
     };


--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2374?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I9b0ea680539846b287d5a5b77f981437f7dc7835
Gerrit-Change-Number: 2374
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
  • [Openvpn-devel] [S] Chan... Code Review

Reply via email to