Skip to content

Commit 7617785

Browse files
committed
Patched with rdp2tcp.patch.txt from Artur Zaprzała
(https://github.com/ArturZaprzala) as posted in FreeRDP/FreeRDP#935.
1 parent 469faae commit 7617785

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

client/channel.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int channel_read_event(void)
9595
{
9696
ssize_t r;
9797
char *ptr;
98-
unsigned int msglen, avail;
98+
unsigned int len, msglen, avail;
9999

100100
//trace_chan("");
101101

@@ -113,10 +113,11 @@ int channel_read_event(void)
113113
if (!ptr)
114114
return error("failed to reserve channel memory");
115115

116+
len = msglen;
116117
do {
117118
r = read(RDP_FD_IN, ptr, msglen);
118119
//trace_chan("r=%u/%u", r, msglen);
119-
if (r < 0)
120+
if (r <= 0)
120121
goto chan_read_err;
121122

122123
#ifdef DEBUG
@@ -133,7 +134,7 @@ int channel_read_event(void)
133134
msglen -= r;
134135
} while (msglen > 0);
135136

136-
iobuf_commit(&vc.ibuf, r);
137+
iobuf_commit(&vc.ibuf, len);
137138
commands_parse(&vc.ibuf);
138139
time(&vc.ts);
139140

client/controller.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int dump_sockets(netsock_t *cli)
151151
break;
152152

153153
case NETSOCK_TUNCLI:
154-
if (!ns->state != NETSTATE_CONNECTED) {
154+
if (ns->state != NETSTATE_CONNECTED) {
155155
ret = controller_answer(cli, "tuncli %s tid=%hu",
156156
host1, ns->tid);
157157
break;

common/msgparser.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int commands_parse(iobuf_t *ibuf)
4343
{
4444
unsigned char cmd, *data;
4545
unsigned int off, msg_len, avail;
46+
int rc = 0;
4647
static const unsigned char r2t_min_size[R2TCMD_MAX] = {
4748
3, // R2TCMD_CONN
4849
2, // R2TCMD_CLOSE
@@ -76,27 +77,35 @@ int commands_parse(iobuf_t *ibuf)
7677
off += 4;
7778

7879
cmd = data[off];
79-
if (cmd >= R2TCMD_MAX)
80-
return error("invalid command id 0x%02x", cmd);
80+
unsigned char *msg = data+off;
81+
off += msg_len;
82+
if (cmd >= R2TCMD_MAX) {
83+
rc = error("invalid command id 0x%02x", cmd);
84+
break;
85+
}
8186

82-
if (msg_len < (unsigned int)r2t_min_size[cmd])
83-
return error("command 0x%02x too short 0x%08x < 0x%08x",
87+
if (msg_len < (unsigned int)r2t_min_size[cmd]) {
88+
rc = error("command 0x%02x too short 0x%08x < 0x%08x",
8489
cmd, msg_len, (unsigned int)r2t_min_size[cmd]);
90+
break;
91+
}
8592

86-
if (!cmd_handlers[cmd])
87-
return error("command 0x%02x not supported", cmd);
93+
if (!cmd_handlers[cmd]) {
94+
rc = error("command 0x%02x not supported", cmd);
95+
break;
96+
}
8897

8998
// call specific command handler
90-
if (cmd_handlers[cmd]((const r2tmsg_t*)(data+off), msg_len))
91-
return -1;
92-
93-
off += msg_len;
99+
if (cmd_handlers[cmd]((const r2tmsg_t*)msg, msg_len)) {
100+
rc = -1;
101+
break;
102+
}
94103
}
95104

96105
if (off > 0)
97106
iobuf_consume(ibuf, off);
98107

99-
return 0;
108+
return rc;
100109
}
101110

102111
// R2TERR_xxx error strings

common/print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int error(const char *fmt, ...)
169169
*/
170170
void print_xfer(const char *name, char rw, unsigned int size)
171171
{
172-
info(1, (rw=='r'?"%-6s < %-8u":"%-6s %8u >"), name, size);
172+
debug(1, (rw=='r'?"%-6s < %-8u":"%-6s %8u >"), name, size);
173173
}
174174

175175
#ifdef DEBUG

server/Makefile.mingw32

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
BIN=rdp2tcp.exe
2-
CC=i586-mingw32msvc-gcc
2+
# CC=i586-mingw32msvc-gcc
3+
CC=i686-w64-mingw32-gcc
34
CFLAGS=-Wall -g \
45
-D_WIN32_WINNT=0x0501 \
56
-I../common

server/aio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int __aio_init_forward(aio_t *rio, aio_t *wio
6161

6262
rio->io.hEvent = evt1;
6363
wio->io.hEvent = evt2;
64-
rio->min_io_size = 1024;
64+
rio->min_io_size = 2048;
6565
wio->min_io_size = 0;
6666

6767
return 0;

server/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int channel_write_event(void)
144144
vc.connected ^= 1;
145145
}
146146

147-
return 0;
147+
return ret;
148148
}
149149

150150
/**

server/tunnel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ static unsigned char wsa_to_r2t_error(int err)
6767
*/
6868
static unsigned char tunnel_generate_id(void)
6969
{
70-
int ok;
7170
unsigned char tid;
7271
static unsigned char last_tid = 0xff;
7372

74-
ok = 1;
7573
for (tid=last_tid+1; tid!=last_tid; ++tid) {
7674
if (!tunnel_lookup(tid)) {
7775
last_tid = tid;
@@ -504,6 +502,8 @@ int tunnel_event(tunnel_t *tun, HANDLE h)
504502
if ((ret >= 0) && (evt & FD_READ)) {
505503
debug(0, "FD_READ");
506504
ret = tunnel_sockrecv_event(tun);
505+
if (evt & FD_CLOSE)
506+
while ((ret = tunnel_sockrecv_event(tun)) > 0);
507507
}
508508

509509
if (evt & FD_CLOSE) {

0 commit comments

Comments
 (0)