diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 71b7167..0f89876 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -290,7 +290,6 @@
     struct buffer buf = alloc_buf_gc(len, &gc);
     if (tls_rec_payload(c->c2.tls_multi, &buf))
     {
-
         while (BLEN(&buf) > 1)
         {
             /* commands on the control channel are seperated by 0x00 bytes.
@@ -300,19 +299,28 @@
             if (cmdlen < BLEN(&buf))
             {
                 /* include the NUL byte and ensure NUL termination */
-                int cmdlen = (int)strlen(BSTR(&buf)) + 1;
+                int buflen = (int)strlen(BSTR(&buf)) + 1;
 
                 /* Construct a buffer that only holds the current command and
                  * its closing NUL byte */
-                struct buffer cmdbuf = alloc_buf_gc(cmdlen, &gc);
-                buf_write(&cmdbuf, BPTR(&buf), cmdlen);
+                struct buffer cmdbuf = alloc_buf_gc(buflen, &gc);
+                buf_write(&cmdbuf, BPTR(&buf), buflen);
+
+                /* Remove \r and \n at the end of the buffer to avoid
+                 * problems with scripts and other that add extra \r and \n */
+                while (BLEN(&cmdbuf)
+                       && (*(BEND(&cmdbuf) - 2) == '\r' || *(BEND(&cmdbuf) - 2)== '\n'))
+                {
+                    *(BEND(&cmdbuf) - 2) = '\0';
+                    buf_inc_len(&cmdbuf, -1);
+                }
 
                 /* check we have only printable characters or null byte in the
                  * command string and no newlines */
-                if (!string_check_buf(&buf, CC_PRINT | CC_NULL, CC_CRLF))
+                if (!string_check_buf(&cmdbuf, CC_PRINT | CC_NULL, CC_CRLF))
                 {
                     msg(D_PUSH_ERRORS, "WARNING: Received control with invalid characters: %s",
-                        format_hex(BPTR(&buf), BLEN(&buf), 256, &gc));
+                        format_hex(BPTR(&buf), BLEN(&cmdbuf), 256, &gc));
                 }
                 else
                 {
