File xrdp-CVE-2017-16927.patch of Package xrdp.29105

From ebd0510a7d4dab906b6e01570205dfa530d1f7bf Mon Sep 17 00:00:00 2001
From: speidy <speidy@gmail.com>
Date: Wed, 22 Nov 2017 02:32:28 +0200
Subject: [PATCH] sesman: scpv0, accept variable length data fields

---
 sesman/libscp/libscp_v0.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

Index: b/sesman/libscp/libscp_v0.c
===================================================================
--- a/sesman/libscp/libscp_v0.c	2016-08-01 15:28:23.000000000 +0800
+++ b/sesman/libscp/libscp_v0.c	2018-04-03 17:52:16.114019558 +0800
@@ -157,7 +157,7 @@
     struct SCP_SESSION *session = 0;
     tui16 sz;
     tui32 code = 0;
-    char buf[257];
+    char *buf = 0;
 
     if (!skipVchk)
     {
@@ -222,27 +222,31 @@
 
         /* reading username */
         in_uint16_be(c->in_s, sz);
-        buf[sz] = '\0';
+        buf = g_new0(char, sz + 1);
         in_uint8a(c->in_s, buf, sz);
-
+        buf[sz] = '\0';
         if (0 != scp_session_set_username(session, buf))
         {
             scp_session_destroy(session);
             log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);
+            g_free(buf);
             return SCP_SERVER_STATE_INTERNAL_ERR;
         }
+        g_free(buf);
 
         /* reading password */
         in_uint16_be(c->in_s, sz);
-        buf[sz] = '\0';
+        buf = g_new0(char, sz + 1);
         in_uint8a(c->in_s, buf, sz);
-
+        buf[sz] = '\0';
         if (0 != scp_session_set_password(session, buf))
         {
             scp_session_destroy(session);
             log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__);
+            g_free(buf);
             return SCP_SERVER_STATE_INTERNAL_ERR;
         }
+        g_free(buf);
 
         /* width */
         in_uint16_be(c->in_s, sz);
@@ -261,9 +265,11 @@
 
             if (sz > 0)
             {
+                buf = g_new0(char, sz + 1);
                 in_uint8a(c->in_s, buf, sz);
                 buf[sz] = '\0';
                 scp_session_set_domain(session, buf);
+                g_free(buf);
             }
         }
 
@@ -274,9 +280,11 @@
 
             if (sz > 0)
             {
+                buf = g_new0(char, sz + 1);
                 in_uint8a(c->in_s, buf, sz);
                 buf[sz] = '\0';
                 scp_session_set_program(session, buf);
+                g_free(buf);
             }
         }
 
@@ -287,9 +295,11 @@
 
             if (sz > 0)
             {
+                buf = g_new0(char, sz + 1);
                 in_uint8a(c->in_s, buf, sz);
                 buf[sz] = '\0';
                 scp_session_set_directory(session, buf);
+                g_free(buf);
             }
         }
 
@@ -300,9 +310,11 @@
 
             if (sz > 0)
             {
+                buf = g_new0(char, sz + 1);
                 in_uint8a(c->in_s, buf, sz);
                 buf[sz] = '\0';
                 scp_session_set_client_ip(session, buf);
+                g_free(buf);
             }
         }
     }
@@ -321,29 +333,35 @@
         scp_session_set_type(session, SCP_GW_AUTHENTICATION);
         /* reading username */
         in_uint16_be(c->in_s, sz);
-        buf[sz] = '\0';
+        buf = g_new0(char, sz + 1);
         in_uint8a(c->in_s, buf, sz);
+        buf[sz] = '\0';
 
         /* g_writeln("Received user name: %s",buf); */
         if (0 != scp_session_set_username(session, buf))
         {
             scp_session_destroy(session);
             /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting        username", __LINE__);*/
+            g_free(buf);
             return SCP_SERVER_STATE_INTERNAL_ERR;
         }
+        g_free(buf);
 
         /* reading password */
         in_uint16_be(c->in_s, sz);
-        buf[sz] = '\0';
+        buf = g_new0(char, sz + 1);
         in_uint8a(c->in_s, buf, sz);
+        buf[sz] = '\0';
 
         /* g_writeln("Received password: %s",buf); */
         if (0 != scp_session_set_password(session, buf))
         {
             scp_session_destroy(session);
             /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */
+            g_free(buf);
             return SCP_SERVER_STATE_INTERNAL_ERR;
         }
+        g_free(buf);
     }
     else
     {
Index: b/common/os_calls.h
===================================================================
--- a/common/os_calls.h	2016-08-01 15:28:23.000000000 +0800
+++ b/common/os_calls.h	2018-04-03 17:55:42.079368699 +0800
@@ -168,4 +168,7 @@
 int APP_CC      g_shmdt(const void *shmaddr);
 int APP_CC      g_gethostname(char *name, int len);
 
+#define g_new0(struct_type, n_structs) \
+        (struct_type *) calloc((n_structs), sizeof(struct_type))
+
 #endif
openSUSE Build Service is sponsored by