Fixed warnings found by compiler and static analysis.

This commit is contained in:
Armin Novak 2019-01-24 11:14:06 +01:00
parent 7b92b91d9a
commit 728cdfd689
2 changed files with 43 additions and 21 deletions

View File

@ -267,8 +267,11 @@ static UINT wlf_cliprdr_send_data_response(wfClipboard* clipboard, const BYTE* d
size_t size) size_t size)
{ {
CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 }; CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
if (size > UINT32_MAX)
return ERROR_INVALID_PARAMETER;
response.msgFlags = (data) ? CB_RESPONSE_OK : CB_RESPONSE_FAIL; response.msgFlags = (data) ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
response.dataLen = size; response.dataLen = (UINT32)size;
response.requestedFormatData = data; response.requestedFormatData = data;
return clipboard->context->ClientFormatDataResponse(clipboard->context, return clipboard->context->ClientFormatDataResponse(clipboard->context,
&response); &response);
@ -355,6 +358,7 @@ static UINT wlf_cliprdr_monitor_ready(CliprdrClientContext* context,
wfClipboard* clipboard = (wfClipboard*) context->custom; wfClipboard* clipboard = (wfClipboard*) context->custom;
UINT ret; UINT ret;
WINPR_UNUSED(monitorReady);
if ((ret = wlf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK) if ((ret = wlf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK)
return ret; return ret;
@ -592,8 +596,9 @@ static UINT wlf_cliprdr_server_format_list_response(CliprdrClientContext*
static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context, static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context,
const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{ {
int cnv;
UINT rc; UINT rc;
char* data; BYTE* data;
LPWSTR cdata; LPWSTR cdata;
size_t size; size_t size;
const char* mime; const char* mime;
@ -632,10 +637,22 @@ static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context
switch (formatId) switch (formatId)
{ {
case CF_UNICODETEXT: case CF_UNICODETEXT:
size = ConvertToUnicode(CP_UTF8, 0, data, size, &cdata, 0); if (size > INT_MAX)
free(data); rc = ERROR_INTERNAL_ERROR;
data = cdata; else
size *= sizeof(WCHAR); {
cnv = ConvertToUnicode(CP_UTF8, 0, (LPCSTR)data, (int)size, &cdata, 0);
free(data);
if (cnv < 0)
rc = ERROR_INTERNAL_ERROR;
else
{
size = (size_t)cnv;
data = (BYTE*)cdata;
size *= sizeof(WCHAR);
}
}
break; break;
default: default:
@ -656,18 +673,25 @@ static UINT wlf_cliprdr_server_format_data_request(CliprdrClientContext* context
static UINT wlf_cliprdr_server_format_data_response(CliprdrClientContext* static UINT wlf_cliprdr_server_format_data_response(CliprdrClientContext*
context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{ {
int cnv;
UINT rc = ERROR_INTERNAL_ERROR; UINT rc = ERROR_INTERNAL_ERROR;
BOOL freedata = FALSE;
UINT32 size = formatDataResponse->dataLen; UINT32 size = formatDataResponse->dataLen;
LPSTR data = formatDataResponse->requestedFormatData; LPSTR cdata = NULL;
const WCHAR* wdata = (WCHAR*)formatDataResponse->requestedFormatData; LPCSTR data = (LPCSTR)formatDataResponse->requestedFormatData;
const WCHAR* wdata = (const WCHAR*)formatDataResponse->requestedFormatData;
wfClipboard* clipboard = (wfClipboard*) context->custom; wfClipboard* clipboard = (wfClipboard*) context->custom;
if (size > INT_MAX * sizeof(WCHAR))
return ERROR_INTERNAL_ERROR;
switch (clipboard->responseFormat) switch (clipboard->responseFormat)
{ {
case CF_UNICODETEXT: case CF_UNICODETEXT:
size = ConvertFromUnicode(CP_UTF8, 0, wdata, size / sizeof(WCHAR), &data, 0, NULL, NULL); cnv = ConvertFromUnicode(CP_UTF8, 0, wdata, (int)(size / sizeof(WCHAR)), &cdata, 0, NULL, NULL);
freedata = TRUE; if (cnv < 0)
return ERROR_INTERNAL_ERROR;
size = (size_t)cnv;
data = cdata;
break; break;
default: default:
@ -678,10 +702,7 @@ static UINT wlf_cliprdr_server_format_data_response(CliprdrClientContext*
fwrite(data, 1, size, clipboard->responseFile); fwrite(data, 1, size, clipboard->responseFile);
fclose(clipboard->responseFile); fclose(clipboard->responseFile);
rc = CHANNEL_RC_OK; rc = CHANNEL_RC_OK;
fail: free(cdata);
if (freedata)
free(data);
return rc; return rc;
} }
@ -775,6 +796,8 @@ static UINT wlf_cliprdr_clipboard_file_size_failure(wClipboardDelegate* delegate
{ {
CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 }; CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 };
wfClipboard* clipboard = delegate->custom; wfClipboard* clipboard = delegate->custom;
WINPR_UNUSED(errorCode);
response.msgFlags = CB_RESPONSE_FAIL; response.msgFlags = CB_RESPONSE_FAIL;
response.streamId = request->streamId; response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_SIZE; response.dwFlags = FILECONTENTS_SIZE;
@ -790,7 +813,7 @@ static UINT wlf_cliprdr_clipboard_file_range_success(wClipboardDelegate* delegat
response.streamId = request->streamId; response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_RANGE; response.dwFlags = FILECONTENTS_RANGE;
response.cbRequested = size; response.cbRequested = size;
response.requestedData = (BYTE*) data; response.requestedData = (const BYTE*) data;
return clipboard->context->ClientFileContentsResponse(clipboard->context, &response); return clipboard->context->ClientFileContentsResponse(clipboard->context, &response);
} }
@ -799,6 +822,8 @@ static UINT wlf_cliprdr_clipboard_file_range_failure(wClipboardDelegate* delegat
{ {
CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 }; CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 };
wfClipboard* clipboard = delegate->custom; wfClipboard* clipboard = delegate->custom;
WINPR_UNUSED(errorCode);
response.msgFlags = CB_RESPONSE_FAIL; response.msgFlags = CB_RESPONSE_FAIL;
response.streamId = request->streamId; response.streamId = request->streamId;
response.dwFlags = FILECONTENTS_RANGE; response.dwFlags = FILECONTENTS_RANGE;
@ -825,9 +850,6 @@ wfClipboard* wlf_clipboard_new(wlfContext* wfc)
clipboard->delegate->ClipboardFileRangeSuccess = wlf_cliprdr_clipboard_file_range_success; clipboard->delegate->ClipboardFileRangeSuccess = wlf_cliprdr_clipboard_file_range_success;
clipboard->delegate->ClipboardFileRangeFailure = wlf_cliprdr_clipboard_file_range_failure; clipboard->delegate->ClipboardFileRangeFailure = wlf_cliprdr_clipboard_file_range_failure;
return clipboard; return clipboard;
error:
wlf_clipboard_free(clipboard);
return NULL;
} }
void wlf_clipboard_free(wfClipboard* clipboard) void wlf_clipboard_free(wfClipboard* clipboard)

View File

@ -203,7 +203,7 @@ struct _CLIPRDR_FORMAT_DATA_RESPONSE
{ {
DEFINE_CLIPRDR_HEADER_COMMON(); DEFINE_CLIPRDR_HEADER_COMMON();
BYTE* requestedFormatData; const BYTE* requestedFormatData;
}; };
typedef struct _CLIPRDR_FORMAT_DATA_RESPONSE CLIPRDR_FORMAT_DATA_RESPONSE; typedef struct _CLIPRDR_FORMAT_DATA_RESPONSE CLIPRDR_FORMAT_DATA_RESPONSE;
@ -229,7 +229,7 @@ struct _CLIPRDR_FILE_CONTENTS_RESPONSE
UINT32 streamId; UINT32 streamId;
UINT32 dwFlags; UINT32 dwFlags;
UINT32 cbRequested; UINT32 cbRequested;
BYTE* requestedData; const BYTE* requestedData;
}; };
typedef struct _CLIPRDR_FILE_CONTENTS_RESPONSE CLIPRDR_FILE_CONTENTS_RESPONSE; typedef struct _CLIPRDR_FILE_CONTENTS_RESPONSE CLIPRDR_FILE_CONTENTS_RESPONSE;