Gert Doering has submitted this change. ( 
https://gerrit.openvpn.net/c/openvpn/+/2073?usp=email )

Change subject: Increase the buffer size for alert-message in management 
user-pass query
......................................................................

Increase the buffer size for alert-message in management user-pass query

Increase the buffer size from 128 to 256 to accommodate a reasonably
long username and static challenge message when both are included in
the prompt. Print a warning if the text is truncated.

If the encoded " UN:<username-base64>" string is longer than 128 bytes,
skip adding it to the prompt. Print a warning. This caters to up to
about 90 bytes long usernames.

Change-Id: Iea14ef08268e6f6309e4bac4acff27958da8b045
Signed-off-by: Selva Nair <[email protected]>
Acked-by: Razvan Cojocaru <[email protected]>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2073
Message-Id: <[email protected]>
URL: 
https://www.mail-archive.com/[email protected]/msg40361.html
Signed-off-by: Gert Doering <[email protected]>
---
M src/openvpn/manage.c
1 file changed, 16 insertions(+), 8 deletions(-)




diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 65e2881..16864c8 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -3618,7 +3618,7 @@
     {
         volatile int signal_received = 0;
         const bool standalone_disabled_save = man->persist.standalone_disabled;
-        struct buffer alert_msg = alloc_buf_gc(128, &gc);
+        struct buffer alert_msg = alloc_buf_gc(256, &gc);
         const char *alert_type = NULL;
         const char *prefix = NULL;
         unsigned int up_query_mode = 0;
@@ -3680,23 +3680,31 @@
              * Indicate it in the prompt as base64 encoded.
              */
             char *user64 = NULL;
-            if (openvpn_base64_encode(up->username, (int)strlen(up->username), 
&user64) != -1)
+            const int user64_len = openvpn_base64_encode(up->username, 
(int)strlen(up->username), &user64);
+            if (user64_len == -1)
             {
-                buf_printf(&alert_msg, " UN:%s", user64);
+                msg(M_NONFATAL, "ERROR: could not base64-encode username");
+            }
+            else if (user64_len + 4 > 128)
+            {
+                msg(M_WARN | M_INFO, "Preferred username too long for 
user-pass prompt sent to management; omitting UN:<username> hint.");
             }
             else
             {
-                msg(M_NONFATAL, "ERROR: could not base64-encode username");
+                buf_printf(&alert_msg, " UN:%s", user64);
             }
             free(user64);
         }

         if (sc)
         {
-            buf_printf(&alert_msg, " SC:%d,%s",
-                       BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_ECHO)
-                           | (BOOL_CAST(flags & 
GET_USER_PASS_STATIC_CHALLENGE_CONCAT) << 1),
-                       sc);
+            if (!buf_printf(&alert_msg, " SC:%d,%s",
+                            BOOL_CAST(flags & 
GET_USER_PASS_STATIC_CHALLENGE_ECHO)
+                                | (BOOL_CAST(flags & 
GET_USER_PASS_STATIC_CHALLENGE_CONCAT) << 1),
+                            sc))
+            {
+                msg(M_WARN | M_INFO, "SC:<challenge-text> in user-pass prompt 
sent to management got truncated.");
+            }
         }

         man_wait_for_client_connection(man, &signal_received, 0, 
MWCC_PASSWORD_WAIT);

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

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iea14ef08268e6f6309e4bac4acff27958da8b045
Gerrit-Change-Number: 2073
Gerrit-PatchSet: 3
Gerrit-Owner: Selva Nair <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to