Skip to content

Commit

Permalink
Merge pull request FreeRDP#4627 from akallabeth/clang_warning_fixes
Browse files Browse the repository at this point in the history
Clang warning fixes
  • Loading branch information
mfleisz authored May 4, 2018
2 parents 65e3297 + 87c19b3 commit 9c02f1b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 62 deletions.
2 changes: 1 addition & 1 deletion channels/rail/client/rail_orders.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ UINT rail_order_recv(railPlugin* rail, wStream* s)

case RDP_RAIL_ORDER_EXEC_RESULT:
{
RAIL_EXEC_RESULT_ORDER execResult;
RAIL_EXEC_RESULT_ORDER execResult = { 0 };
error = rail_recv_exec_result_order(rail, &execResult, s);
free(execResult.exeOrFile.string);
return error;
Expand Down
9 changes: 3 additions & 6 deletions channels/rdpsnd/client/rdpsnd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ static UINT rdpsnd_treat_wave(rdpsndPlugin* rdpsnd, wStream* s, size_t size)
{
BYTE* data;
AUDIO_FORMAT* format;
UINT status;
DWORD end;
DWORD diffMS;
UINT latency = 0;
Expand All @@ -488,20 +487,19 @@ static UINT rdpsnd_treat_wave(rdpsndPlugin* rdpsnd, wStream* s, size_t size)

if (rdpsnd->device && rdpsnd->attached)
{
UINT status = CHANNEL_RC_OK;
wStream* pcmData = StreamPool_Take(rdpsnd->pool, 4096);

if (rdpsnd->device->FormatSupported(rdpsnd->device, format))
{
latency = IFCALLRESULT(0, rdpsnd->device->Play, rdpsnd->device, data, size);
status = CHANNEL_RC_OK;
}
else if (freerdp_dsp_decode(rdpsnd->dsp_context, format, data, size, pcmData))
{
Stream_SealLength(pcmData);
latency = IFCALLRESULT(0, rdpsnd->device->Play, rdpsnd->device, Stream_Buffer(pcmData),
Stream_Length(pcmData));
status = CHANNEL_RC_OK;
}
else
status = ERROR_INTERNAL_ERROR;

StreamPool_Return(rdpsnd->pool, pcmData);

Expand Down Expand Up @@ -1128,7 +1126,6 @@ static UINT rdpsnd_virtual_channel_event_initialized(rdpsndPlugin* rdpsnd,

return CHANNEL_RC_OK;
fail:
rdpsnd_virtual_channel_event_terminated(rdpsnd);
return ERROR_INTERNAL_ERROR;
}

Expand Down
125 changes: 70 additions & 55 deletions libfreerdp/core/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum
};

/* CONN REQ replies in enum. order */
static const char *rplstat[] =
static const char* rplstat[] =
{
"succeeded",
"general SOCKS server failure",
Expand All @@ -68,11 +68,12 @@ static const char *rplstat[] =


static BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port);
static BOOL socks_proxy_connect(BIO* bufferedBio, const char *proxyUsername, const char *proxyPassword, const char* hostname, UINT16 port);
static BOOL socks_proxy_connect(BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port);
void proxy_read_environment(rdpSettings* settings, char* envname);

BOOL proxy_prepare(rdpSettings* settings, const char** lpPeerHostname, UINT16* lpPeerPort,
const char** lpProxyUsername, const char** lpProxyPassword)
const char** lpProxyUsername, const char** lpProxyPassword)
{
/* For TSGateway, find the system HTTPS proxy automatically */
if (!settings->ProxyType)
Expand Down Expand Up @@ -191,8 +192,9 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
return TRUE;
}

BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char *proxyUsername, const char *proxyPassword,
const char* hostname, UINT16 port)
BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword,
const char* hostname, UINT16 port)
{
switch (settings->ProxyType)
{
Expand Down Expand Up @@ -304,9 +306,10 @@ static int recv_socks_reply(BIO* bufferedBio, BYTE* buf, int len, char* reason,
{
int status;

for(;;)
for (;;)
{
status = BIO_read(bufferedBio, buf, len);

if (status > 0)
break;

Expand All @@ -330,7 +333,7 @@ static int recv_socks_reply(BIO* bufferedBio, BYTE* buf, int len, char* reason,
return -1;
}
}

if (status < 2)
{
WLog_ERR(TAG, "SOCKS Proxy reply packet too short (%s)", reason);
Expand All @@ -346,8 +349,9 @@ static int recv_socks_reply(BIO* bufferedBio, BYTE* buf, int len, char* reason,
return status;
}

static BOOL socks_proxy_connect(BIO* bufferedBio, const char *proxyUsername, const char *proxyPassword,
const char* hostname, UINT16 port)
static BOOL socks_proxy_connect(BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword,
const char* hostname, UINT16 port)
{
int status;
int nauthMethods = 1, writeLen = 3;
Expand All @@ -364,68 +368,78 @@ static BOOL socks_proxy_connect(BIO* bufferedBio, const char *proxyUsername, con
buf[0] = 5; /* SOCKS version */
buf[1] = nauthMethods; /* #of methods offered */
buf[2] = AUTH_M_NO_AUTH;

if (nauthMethods > 1)
buf[3] = AUTH_M_USR_PASS;

status = BIO_write(bufferedBio, buf, writeLen);

if (status != writeLen)
{
WLog_ERR(TAG, "SOCKS proxy: failed to write AUTH METHOD request");
return FALSE;
}

status = recv_socks_reply(bufferedBio, buf, 2, "AUTH REQ", 5);

if (status <= 0)
return FALSE;

switch(buf[1])
{
case AUTH_M_NO_AUTH:
WLog_DBG(TAG, "SOCKS Proxy: (NO AUTH) method was selected");
break;
case AUTH_M_USR_PASS:
switch (buf[1])
{
int usernameLen = strnlen(proxyUsername, 255);
int userpassLen = strnlen(proxyPassword, 255);
BYTE *ptr;

if (nauthMethods < 2)
{
WLog_ERR(TAG, "SOCKS Proxy: USER/PASS method was not proposed to server");
return FALSE;
}
case AUTH_M_NO_AUTH:
WLog_DBG(TAG, "SOCKS Proxy: (NO AUTH) method was selected");
break;

/* user/password v1 method */
ptr = buf + 2;
buf[0] = 1;
buf[1] = usernameLen;
memcpy(ptr, proxyUsername, usernameLen);
ptr += usernameLen;
*ptr = userpassLen;
ptr++;
memcpy(ptr, proxyPassword, userpassLen);

status = BIO_write(bufferedBio, buf, 3 + usernameLen + userpassLen);
if (status != 3 + usernameLen + userpassLen)
{
WLog_ERR(TAG, "SOCKS Proxy: error writing user/password request");
return FALSE;
}
case AUTH_M_USR_PASS:
if (!proxyUsername || !proxyPassword)
return FALSE;
else
{
int usernameLen = strnlen(proxyUsername, 255);
int userpassLen = strnlen(proxyPassword, 255);
BYTE* ptr;

if (nauthMethods < 2)
{
WLog_ERR(TAG, "SOCKS Proxy: USER/PASS method was not proposed to server");
return FALSE;
}

/* user/password v1 method */
ptr = buf + 2;
buf[0] = 1;
buf[1] = usernameLen;
memcpy(ptr, proxyUsername, usernameLen);
ptr += usernameLen;
*ptr = userpassLen;
ptr++;
memcpy(ptr, proxyPassword, userpassLen);
status = BIO_write(bufferedBio, buf, 3 + usernameLen + userpassLen);

if (status != 3 + usernameLen + userpassLen)
{
WLog_ERR(TAG, "SOCKS Proxy: error writing user/password request");
return FALSE;
}

status = recv_socks_reply(bufferedBio, buf, 2, "AUTH REQ", 1);

if (status < 2)
return FALSE;

if (buf[1] != 0x00)
{
WLog_ERR(TAG, "SOCKS Proxy: invalid user/password");
return FALSE;
}
}

status = recv_socks_reply(bufferedBio, buf, 2, "AUTH REQ", 1);
if (status < 2)
return FALSE;
break;

if (buf[1] != 0x00)
{
WLog_ERR(TAG, "SOCKS Proxy: invalid user/password");
default:
WLog_ERR(TAG, "SOCKS Proxy: unknown method 0x%x was selected by proxy", buf[1]);
return FALSE;
}
break;
}
default:
WLog_ERR(TAG, "SOCKS Proxy: unknown method 0x%x was selected by proxy", buf[1]);
return FALSE;
}

/* CONN request */
Expand All @@ -438,15 +452,16 @@ static BOOL socks_proxy_connect(BIO* bufferedBio, const char *proxyUsername, con
/* follows DST.PORT in netw. format */
buf[hostnlen + 5] = (port >> 8) & 0xff;
buf[hostnlen + 6] = port & 0xff;

status = BIO_write(bufferedBio, buf, hostnlen + 7);

if (status != (hostnlen + 7))
{
WLog_ERR(TAG, "SOCKS proxy: failed to write CONN REQ");
return FALSE;
}

status = recv_socks_reply(bufferedBio, buf, sizeof(buf), "CONN REQ", 5);

if (status < 4)
return FALSE;

Expand All @@ -457,9 +472,9 @@ static BOOL socks_proxy_connect(BIO* bufferedBio, const char *proxyUsername, con
}

if (buf[1] > 0 && buf[1] < 9)
WLog_INFO(TAG, "SOCKS Proxy replied: %s", rplstat[buf[1]]);
WLog_INFO(TAG, "SOCKS Proxy replied: %s", rplstat[buf[1]]);
else
WLog_INFO(TAG, "SOCKS Proxy replied: %d status not listed in rfc1928", buf[1]);
WLog_INFO(TAG, "SOCKS Proxy replied: %d status not listed in rfc1928", buf[1]);

return FALSE;
}

0 comments on commit 9c02f1b

Please sign in to comment.