Merge pull request #4237 from akallabeth/remove_atoi

Replaced atoi
This commit is contained in:
Martin Fleisz 2017-11-16 09:39:04 +01:00 committed by GitHub
commit af0ac6daf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1845 additions and 1407 deletions

View File

@ -24,6 +24,7 @@
#include "config.h"
#endif
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
@ -763,6 +764,7 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, ADDIN_ARGV* args)
return FALSE;
arg = audin_args;
errno = 0;
do
{
@ -788,15 +790,28 @@ BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, ADDIN_ARGV* args)
}
CommandLineSwitchCase(arg, "format")
{
audin->fixed_format = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT16_MAX))
return FALSE;
audin->fixed_format = val;
}
CommandLineSwitchCase(arg, "rate")
{
audin->fixed_rate = atoi(arg->Value);
long val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return FALSE;
audin->fixed_rate = val;
}
CommandLineSwitchCase(arg, "channel")
{
audin->fixed_channel = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT16_MAX))
audin->fixed_channel = val;
}
CommandLineSwitchDefault(arg)
{

View File

@ -471,6 +471,7 @@ static UINT audin_oss_parse_addin_args(AudinOSSDevice* device, ADDIN_ARGV* args)
return ERROR_INVALID_PARAMETER;
arg = audin_oss_args;
errno = 0;
do
{
@ -488,7 +489,17 @@ static UINT audin_oss_parse_addin_args(AudinOSSDevice* device, ADDIN_ARGV* args)
return CHANNEL_RC_NO_MEMORY;
}
oss->dev_unit = strtol(str_num, &eptr, 10);
{
long val = strtol(str_num, &eptr, 10);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
{
free(str_num);
return CHANNEL_RC_NULL_DATA;
}
oss->dev_unit = val;
}
if (oss->dev_unit < 0 || *eptr != '\0')
oss->dev_unit = -1;

View File

@ -82,22 +82,25 @@ static int rdpsnd_oss_get_format(AUDIO_FORMAT* format)
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
switch (format->wBitsPerSample)
{
case 8:
return AFMT_S8;
case 16:
return AFMT_S16_LE;
}
break;
case WAVE_FORMAT_ALAW:
return AFMT_A_LAW;
#if 0 /* This does not work on my desktop. */
case WAVE_FORMAT_MULAW:
return AFMT_MU_LAW;
#endif
case WAVE_FORMAT_ADPCM:
case WAVE_FORMAT_DVI_ADPCM:
return AFMT_S16_LE;
@ -117,20 +120,19 @@ static BOOL rdpsnd_oss_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
if (format->cbSize != 0 ||
format->nSamplesPerSec > 48000 ||
(format->wBitsPerSample != 8 && format->wBitsPerSample != 16) ||
(format->nChannels != 1 && format->nChannels != 2))
format->nSamplesPerSec > 48000 ||
(format->wBitsPerSample != 8 && format->wBitsPerSample != 16) ||
(format->nChannels != 1 && format->nChannels != 2))
return FALSE;
break;
case WAVE_FORMAT_ADPCM:
case WAVE_FORMAT_DVI_ADPCM:
if (format->nSamplesPerSec > 48000 ||
format->wBitsPerSample != 4 ||
(format->nChannels != 1 && format->nChannels != 2))
format->wBitsPerSample != 4 ||
(format->nChannels != 1 && format->nChannels != 2))
return FALSE;
break;
@ -379,17 +381,19 @@ static BOOL rdpsnd_oss_wave_decode(rdpsndDevicePlugin* device, RDPSND_WAVE* wave
{
case WAVE_FORMAT_ADPCM:
oss->dsp_context->decode_ms_adpcm(oss->dsp_context,
wave->data, wave->length, oss->format.nChannels, oss->format.nBlockAlign);
wave->data, wave->length, oss->format.nChannels, oss->format.nBlockAlign);
wave->length = oss->dsp_context->adpcm_size;
wave->data = oss->dsp_context->adpcm_buffer;
break;
case WAVE_FORMAT_DVI_ADPCM:
oss->dsp_context->decode_ima_adpcm(oss->dsp_context,
wave->data, wave->length, oss->format.nChannels, oss->format.nBlockAlign);
wave->data, wave->length, oss->format.nChannels, oss->format.nBlockAlign);
wave->length = oss->dsp_context->adpcm_size;
wave->data = oss->dsp_context->adpcm_buffer;
break;
}
return TRUE;
}
@ -442,12 +446,14 @@ static int rdpsnd_oss_parse_addin_args(rdpsndDevicePlugin* device, ADDIN_ARGV* a
COMMAND_LINE_ARGUMENT_A* arg;
rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device;
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, rdpsnd_oss_args, flags, oss, NULL, NULL);
status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, rdpsnd_oss_args, flags,
oss, NULL, NULL);
if (status < 0)
return status;
arg = rdpsnd_oss_args;
errno = 0;
do
{
@ -458,10 +464,21 @@ static int rdpsnd_oss_parse_addin_args(rdpsndDevicePlugin* device, ADDIN_ARGV* a
CommandLineSwitchCase(arg, "dev")
{
str_num = _strdup(arg->Value);
if (!str_num)
return ERROR_OUTOFMEMORY;
oss->dev_unit = strtol(str_num, &eptr, 10);
{
long val = strtol(str_num, &eptr, 10);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
{
free(str_num);
return CHANNEL_RC_NULL_DATA;
}
oss->dev_unit = val;
}
if (oss->dev_unit < 0 || *eptr != '\0')
oss->dev_unit = -1;
@ -491,8 +508,10 @@ UINT freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS p
ADDIN_ARGV* args;
rdpsndOssPlugin* oss;
oss = (rdpsndOssPlugin*)calloc(1, sizeof(rdpsndOssPlugin));
if (!oss)
return CHANNEL_RC_NO_MEMORY;
oss->device.Open = rdpsnd_oss_open;
oss->device.FormatSupported = rdpsnd_oss_format_supported;
oss->device.SetFormat = rdpsnd_oss_set_format;
@ -508,6 +527,7 @@ UINT freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS p
args = pEntryPoints->args;
rdpsnd_oss_parse_addin_args((rdpsndDevicePlugin*)oss, args);
oss->dsp_context = freerdp_dsp_context_new();
if (!oss->dsp_context)
{
free(oss);
@ -515,6 +535,5 @@ UINT freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS p
}
pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)oss);
return CHANNEL_RC_OK;
}

View File

@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/wlog.h>
@ -224,8 +225,8 @@ static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd)
return;
rdpsnd->ClientFormats = (AUDIO_FORMAT*) calloc(
rdpsnd->NumberOfServerFormats,
sizeof(AUDIO_FORMAT));
rdpsnd->NumberOfServerFormats,
sizeof(AUDIO_FORMAT));
if (!rdpsnd->ClientFormats)
return;
@ -871,6 +872,7 @@ static UINT rdpsnd_process_addin_args(rdpsndPlugin* rdpsnd, ADDIN_ARGV* args)
return CHANNEL_RC_INITIALIZATION_ERROR;
arg = rdpsnd_args;
errno = 0;
do
{
@ -890,23 +892,43 @@ static UINT rdpsnd_process_addin_args(rdpsndPlugin* rdpsnd, ADDIN_ARGV* args)
}
CommandLineSwitchCase(arg, "format")
{
rdpsnd->fixedFormat = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT16_MAX))
return CHANNEL_RC_INITIALIZATION_ERROR;
rdpsnd->fixedFormat = val;
}
CommandLineSwitchCase(arg, "rate")
{
rdpsnd->fixedRate = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return CHANNEL_RC_INITIALIZATION_ERROR;
rdpsnd->fixedRate = val;
}
CommandLineSwitchCase(arg, "channel")
{
rdpsnd->fixedChannel = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT16_MAX))
return CHANNEL_RC_INITIALIZATION_ERROR;
rdpsnd->fixedChannel = val;
}
CommandLineSwitchCase(arg, "latency")
{
rdpsnd->latency = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return CHANNEL_RC_INITIALIZATION_ERROR;
rdpsnd->latency = val;
}
CommandLineSwitchCase(arg, "quality")
{
int wQualityMode = DYNAMIC_QUALITY;
long wQualityMode = DYNAMIC_QUALITY;
if (_stricmp(arg->Value, "dynamic") == 0)
wQualityMode = DYNAMIC_QUALITY;
@ -915,7 +937,12 @@ static UINT rdpsnd_process_addin_args(rdpsndPlugin* rdpsnd, ADDIN_ARGV* args)
else if (_stricmp(arg->Value, "high") == 0)
wQualityMode = HIGH_QUALITY;
else
wQualityMode = atoi(arg->Value);
{
wQualityMode = strtol(arg->Value, NULL, 0);
if (errno != 0)
return CHANNEL_RC_INITIALIZATION_ERROR;
}
if ((wQualityMode < 0) || (wQualityMode > 2))
wQualityMode = DYNAMIC_QUALITY;

File diff suppressed because it is too large Load Diff

View File

@ -35,16 +35,16 @@
int libusb_debug;
#define BASIC_STATE_FUNC_DEFINED(_arg, _type) \
static _type udevman_get_##_arg (IUDEVMAN* idevman) \
{ \
UDEVMAN * udevman = (UDEVMAN *) idevman; \
return udevman->_arg; \
} \
static void udevman_set_##_arg (IUDEVMAN* idevman, _type _t) \
{ \
UDEVMAN * udevman = (UDEVMAN *) idevman; \
udevman->_arg = _t; \
}
static _type udevman_get_##_arg (IUDEVMAN* idevman) \
{ \
UDEVMAN * udevman = (UDEVMAN *) idevman; \
return udevman->_arg; \
} \
static void udevman_set_##_arg (IUDEVMAN* idevman, _type _t) \
{ \
UDEVMAN * udevman = (UDEVMAN *) idevman; \
udevman->_arg = _t; \
}
#define BASIC_STATE_FUNC_REGISTER(_arg, _man) \
_man->iface.get_##_arg = udevman_get_##_arg; \
@ -90,17 +90,14 @@ static IUDEVICE* udevman_get_next(IUDEVMAN* idevman)
{
UDEVMAN* udevman = (UDEVMAN*) idevman;
IUDEVICE* pdev;
pdev = udevman->idev;
udevman->idev = (IUDEVICE*) ((UDEVICE*) udevman->idev)->next;
udevman->idev = (IUDEVICE*)((UDEVICE*) udevman->idev)->next;
return pdev;
}
static IUDEVICE* udevman_get_udevice_by_addr(IUDEVMAN* idevman, int bus_number, int dev_number)
{
IUDEVICE* pdev;
idevman->loading_lock(idevman);
idevman->rewind(idevman);
@ -117,23 +114,22 @@ static IUDEVICE* udevman_get_udevice_by_addr(IUDEVMAN* idevman, int bus_number,
idevman->loading_unlock(idevman);
WLog_WARN(TAG, "bus:%d dev:%d not exist in udevman",
bus_number, dev_number);
bus_number, dev_number);
return NULL;
}
static int udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_number,
int UsbDevice, UINT16 idVendor, UINT16 idProduct, int flag)
int UsbDevice, UINT16 idVendor, UINT16 idProduct, int flag)
{
UDEVMAN* udevman = (UDEVMAN*) idevman;
IUDEVICE* pdev = NULL;
IUDEVICE** devArray;
int i, num, addnum = 0;
pdev = (IUDEVICE*) udevman_get_udevice_by_addr(idevman, bus_number, dev_number);
if (pdev != NULL)
return 0;
if (flag == UDEVMAN_FLAG_ADD_BY_ADDR)
{
pdev = udev_new_by_addr(bus_number, dev_number);
@ -171,8 +167,8 @@ static int udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_n
{
pdev = devArray[i];
if (udevman_get_udevice_by_addr(idevman,
pdev->get_bus_number(pdev), pdev->get_dev_number(pdev)) != NULL)
if (udevman_get_udevice_by_addr(idevman,
pdev->get_bus_number(pdev), pdev->get_dev_number(pdev)) != NULL)
{
zfree(pdev);
continue;
@ -215,11 +211,9 @@ static int udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_n
static int udevman_unregister_udevice(IUDEVMAN* idevman, int bus_number, int dev_number)
{
UDEVMAN* udevman = (UDEVMAN*) idevman;
UDEVICE * pdev, * dev;
UDEVICE* pdev, * dev;
int ret = 0, err = 0;
dev = (UDEVICE*) udevman_get_udevice_by_addr(idevman, bus_number, dev_number);
idevman->loading_lock(idevman);
idevman->rewind(idevman);
@ -230,7 +224,6 @@ static int udevman_unregister_udevice(IUDEVMAN* idevman, int bus_number, int dev
if (pdev == dev) /* device exists */
{
/* set previous device to point to next device */
if (dev->prev != NULL)
{
/* unregistered device is not the head */
@ -248,7 +241,7 @@ static int udevman_unregister_udevice(IUDEVMAN* idevman, int bus_number, int dev
if (dev->next != NULL)
{
/* unregistered device is not the tail */
pdev = (UDEVICE *)dev->next;
pdev = (UDEVICE*)dev->next;
pdev->prev = dev->prev;
}
else
@ -256,11 +249,12 @@ static int udevman_unregister_udevice(IUDEVMAN* idevman, int bus_number, int dev
/* unregistered device is the tail, update tail */
udevman->tail = (IUDEVICE*)dev->prev;
}
udevman->device_num--;
break;
break;
}
}
idevman->loading_unlock(idevman);
if (dev)
@ -269,28 +263,31 @@ static int udevman_unregister_udevice(IUDEVMAN* idevman, int bus_number, int dev
if (err != LIBUSB_ERROR_NO_DEVICE)
{
ret = libusb_reset_device(dev->libusb_handle);
if (ret<0)
if (ret < 0)
{
WLog_ERR(TAG, "libusb_reset_device: ERROR!!ret:%d", ret);
}
}
/* release all interface and attach kernel driver */
dev->iface.attach_kernel_driver((IUDEVICE*)dev);
if(dev->request_queue) zfree(dev->request_queue);
dev->iface.attach_kernel_driver((IUDEVICE*)dev);
if (dev->request_queue) zfree(dev->request_queue);
/* free the config descriptor that send from windows */
msusb_msconfig_free(dev->MsConfig);
libusb_close (dev->libusb_handle);
libusb_close (dev->hub_handle);
libusb_close(dev->libusb_handle);
libusb_close(dev->hub_handle);
sem_destroy(&dev->sem_id);
/* free device info */
if (dev->devDescriptor)
zfree(dev->devDescriptor);
if (dev)
zfree(dev);
zfree(dev);
return 1; /* unregistration successful */
}
@ -302,28 +299,22 @@ static void udevman_parse_device_addr(char* str, int* id1, int* id2, char sign)
{
char s1[8];
char* s2;
ZeroMemory(s1, sizeof(s1));
s2 = (strchr(str, sign)) + 1;
s2 = (strchr(str, sign)) + 1;
strncpy(s1, str, strlen(str) - (strlen(s2) + 1));
*id1 = atoi(s1);
*id2 = atoi(s2);
*id1 = strtol(s1, NULL, 0);
*id2 = strtol(s2, NULL, 0);
}
static void udevman_parse_device_pid_vid(char* str, int* id1, int* id2, char sign)
{
char s1[8];
char* s2;
ZeroMemory(s1, sizeof(s1));
s2 = (strchr(str, sign)) + 1;
s2 = (strchr(str, sign)) + 1;
strncpy(s1, str, strlen(str) - (strlen(s2) + 1));
*id1 = (int) strtol(s1, NULL, 16);
*id2 = (int) strtol(s2, NULL, 16);
*id1 = strtol(s1, NULL, 16);
*id2 = strtol(s2, NULL, 16);
}
static int udevman_check_device_exist_by_id(IUDEVMAN* idevman, UINT16 idVendor, UINT16 idProduct)
@ -358,7 +349,6 @@ static IUDEVICE* udevman_get_udevice_by_UsbDevice_try_again(IUDEVMAN* idevman, U
}
idevman->loading_unlock(idevman);
return NULL;
}
@ -380,9 +370,7 @@ static IUDEVICE* udevman_get_udevice_by_UsbDevice(IUDEVMAN* idevman, UINT32 UsbD
}
idevman->loading_unlock(idevman);
/* try again */
pdev = (UDEVICE*) idevman->get_udevice_by_UsbDevice_try_again(idevman, UsbDevice);
if (pdev)
@ -425,10 +413,8 @@ BASIC_STATE_FUNC_DEFINED(sem_timeout, int)
static void udevman_free(IUDEVMAN* idevman)
{
UDEVMAN* udevman = (UDEVMAN*) idevman;
pthread_mutex_destroy(&udevman->devman_loading);
sem_destroy(&udevman->sem_urb_lock);
libusb_exit(NULL);
/* free udevman */
@ -437,11 +423,10 @@ static void udevman_free(IUDEVMAN* idevman)
zfree(udevman);
}
static void udevman_load_interface(UDEVMAN * udevman)
static void udevman_load_interface(UDEVMAN* udevman)
{
/* standard */
udevman->iface.free = udevman_free;
/* manage devices */
udevman->iface.rewind = udevman_rewind;
udevman->iface.get_next = udevman_get_next;
@ -449,18 +434,15 @@ static void udevman_load_interface(UDEVMAN * udevman)
udevman->iface.register_udevice = udevman_register_udevice;
udevman->iface.unregister_udevice = udevman_unregister_udevice;
udevman->iface.get_udevice_by_UsbDevice = udevman_get_udevice_by_UsbDevice;
udevman->iface.get_udevice_by_UsbDevice_try_again =
udevman_get_udevice_by_UsbDevice_try_again;
udevman->iface.get_udevice_by_UsbDevice_try_again =
udevman_get_udevice_by_UsbDevice_try_again;
/* Extension */
udevman->iface.check_device_exist_by_id = udevman_check_device_exist_by_id;
udevman->iface.isAutoAdd = udevman_is_auto_add;
/* Basic state */
BASIC_STATE_FUNC_REGISTER(defUsbDevice, udevman);
BASIC_STATE_FUNC_REGISTER(device_num, udevman);
BASIC_STATE_FUNC_REGISTER(sem_timeout, udevman);
/* control semaphore or mutex lock */
udevman->iface.loading_lock = udevman_loading_lock;
udevman->iface.loading_unlock = udevman_loading_unlock;
@ -502,7 +484,6 @@ static void urbdrc_udevman_register_devices(UDEVMAN* udevman, char* devices)
dev_number = 0;
idVendor = 0;
idProduct = 0;
strcpy(hardware_id, token);
token = strtok(NULL, "#");
@ -510,14 +491,13 @@ static void urbdrc_udevman_register_devices(UDEVMAN* udevman, char* devices)
{
udevman_parse_device_pid_vid(hardware_id, &idVendor, &idProduct, ':');
success = udevman->iface.register_udevice((IUDEVMAN*) udevman,
0, 0, UsbDevice, (UINT16) idVendor, (UINT16) idProduct, UDEVMAN_FLAG_ADD_BY_VID_PID);
0, 0, UsbDevice, (UINT16) idVendor, (UINT16) idProduct, UDEVMAN_FLAG_ADD_BY_VID_PID);
}
else if (udevman->flags & UDEVMAN_FLAG_ADD_BY_ADDR)
{
udevman_parse_device_addr(hardware_id, &bus_number, &dev_number, ':');
success = udevman->iface.register_udevice((IUDEVMAN*) udevman,
bus_number, dev_number, UsbDevice, 0, 0, UDEVMAN_FLAG_ADD_BY_ADDR);
bus_number, dev_number, UsbDevice, 0, 0, UDEVMAN_FLAG_ADD_BY_ADDR);
}
if (success)
@ -532,12 +512,9 @@ static void urbdrc_udevman_parse_addin_args(UDEVMAN* udevman, ADDIN_ARGV* args)
int status;
DWORD flags;
COMMAND_LINE_ARGUMENT_A* arg;
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
urbdrc_udevman_args, flags, udevman, NULL, NULL);
urbdrc_udevman_args, flags, udevman, NULL, NULL);
arg = urbdrc_udevman_args;
do
@ -546,7 +523,6 @@ static void urbdrc_udevman_parse_addin_args(UDEVMAN* udevman, ADDIN_ARGV* args)
continue;
CommandLineSwitchStart(arg)
CommandLineSwitchCase(arg, "dbg")
{
WLog_SetLogLevel(WLog_Get(TAG), WLOG_TRACE);
@ -569,9 +545,7 @@ static void urbdrc_udevman_parse_addin_args(UDEVMAN* udevman, ADDIN_ARGV* args)
}
CommandLineSwitchDefault(arg)
{
}
CommandLineSwitchEnd(arg)
}
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
@ -587,34 +561,26 @@ int freerdp_urbdrc_client_subsystem_entry(PFREERDP_URBDRC_SERVICE_ENTRY_POINTS p
{
UDEVMAN* udevman;
ADDIN_ARGV* args = pEntryPoints->args;
libusb_init(NULL);
udevman = (PUDEVMAN) malloc(sizeof(UDEVMAN));
if (!udevman)
return -1;
udevman->device_num = 0;
udevman->idev = NULL;
udevman->head = NULL;
udevman->tail = NULL;
udevman->tail = NULL;
udevman->sem_timeout = 0;
udevman->flags = UDEVMAN_FLAG_ADD_BY_VID_PID;
pthread_mutex_init(&udevman->devman_loading, NULL);
sem_init(&udevman->sem_urb_lock, 0, MAX_URB_REQUSET_NUM);
/* load usb device service management */
udevman_load_interface(udevman);
/* set debug flag, to enable Debug message for usb data transfer */
libusb_debug = 10;
urbdrc_udevman_parse_addin_args(udevman, args);
pEntryPoints->pRegisterUDEVMAN(pEntryPoints->plugin, (IUDEVMAN*) udevman);
WLog_DBG(TAG, "UDEVMAN device registered.");
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/wlog.h>
@ -229,12 +230,12 @@ static void freerdp_client_print_command_line_args(COMMAND_LINE_ARGUMENT_A* arg)
|| (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL))
{
BOOL overlong = FALSE;
printf(" %s", "/");
if (arg->Format)
{
size_t length = (strlen(arg->Name) + strlen(arg->Format) + 2);
if (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)
length += 2;
@ -312,6 +313,7 @@ BOOL freerdp_client_print_command_line_help_ex(int argc, char** argv,
printf("Multimedia Redirection: /multimedia:sys:alsa\n");
printf("USB Device Redirection: /usb:id,dev:054c:0268\n");
printf("\n");
printf("For Gateways, the https_proxy environment variable is respected:\n");
#ifdef _WIN32
printf(" set HTTPS_PROXY=http://proxy.contoso.com:3128/\n");
@ -320,6 +322,7 @@ BOOL freerdp_client_print_command_line_help_ex(int argc, char** argv,
#endif
printf(" xfreerdp /g:rdp.contoso.com ...\n");
printf("\n");
printf("More documentation is coming, in the meantime consult source files\n");
printf("\n");
return TRUE;
@ -1063,12 +1066,17 @@ BOOL freerdp_parse_username(char* username, char** user, char** domain)
BOOL freerdp_parse_hostname(char* hostname, char** host, int* port)
{
char* p;
int length;
p = strrchr(hostname, ':');
if (p)
{
length = (p - hostname);
unsigned long val;
SSIZE_T length = (p - hostname);
errno = 0;
val = strtoul(p + 1, NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
return FALSE;
*host = (char*) calloc(length + 1UL, sizeof(char));
if (!(*host))
@ -1076,7 +1084,7 @@ BOOL freerdp_parse_hostname(char* hostname, char** host, int* port)
CopyMemory(*host, hostname, length);
(*host)[length] = '\0';
*port = atoi(p + 1);
*port = val;
}
else
{
@ -1498,6 +1506,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineFindArgumentA(args, "v");
arg = args;
errno = 0;
do
{
@ -1518,8 +1527,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (p)
{
unsigned long val = strtoul(&p[1], NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
length = (int)(p - arg->Value);
settings->ServerPort = atoi(&p[1]);
settings->ServerPort = val;
if (!(settings->ServerHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
@ -1550,7 +1563,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (*(p2 + 1) == ':')
{
settings->ServerPort = atoi(&p2[2]);
unsigned long val = strtoul(&p2[2], NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->ServerPort = val;
}
printf("hostname %s port %"PRIu32"\n", settings->ServerHostname, settings->ServerPort);
@ -1584,11 +1602,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "w")
{
settings->DesktopWidth = atoi(arg->Value);
long val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->DesktopWidth = val;
}
CommandLineSwitchCase(arg, "h")
{
settings->DesktopHeight = atoi(arg->Value);
long val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->DesktopHeight = val;
}
CommandLineSwitchCase(arg, "size")
{
@ -1600,8 +1628,28 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (p)
{
*p = '\0';
settings->DesktopWidth = atoi(str);
settings->DesktopHeight = atoi(&p[1]);
{
long val = strtol(str, NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->DesktopWidth = val;
}
{
long val = strtol(&p[1], NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->DesktopHeight = val;
}
}
else
{
@ -1616,7 +1664,6 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
settings->PercentScreenUseWidth = 1;
partial = TRUE;
}
if (strchr(p, 'h'))
{
settings->PercentScreenUseHeight = 1;
@ -1630,7 +1677,17 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
*p = '\0';
settings->PercentScreen = atoi(str);
{
long val = strtol(str, NULL, 0);
if ((errno != 0) || (val < 0) || (val > 100))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->PercentScreen = val;
}
}
}
@ -1679,7 +1736,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
for (i = 0; i < settings->NumMonitorIds; i++)
{
settings->MonitorIds[i] = atoi(p[i]);
unsigned long val = strtoul(p[i], NULL, 0);
if ((errno != 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->MonitorIds[i] = val;
}
free(p);
@ -1711,9 +1773,26 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if ((p = strchr(str, 'x')))
{
unsigned long w, h;
*p = '\0';
settings->SmartSizingWidth = atoi(str);
settings->SmartSizingHeight = atoi(&p[1]);
w = strtoul(str, NULL, 0);
if ((errno != 0) || (w == 0) || (w > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
h = strtoul(&p[1], NULL, 0);
if ((errno != 0) || (h == 0) || (h > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->SmartSizingWidth = w;
settings->SmartSizingHeight = h;
}
free(str);
@ -1721,7 +1800,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "bpp")
{
settings->ColorDepth = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->ColorDepth = val;
switch (settings->ColorDepth)
{
@ -1763,7 +1847,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "kbd")
{
unsigned long int id;
unsigned long id;
char* pEnd;
id = strtoul(arg->Value, &pEnd, 16);
@ -1772,33 +1856,49 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (id == 0)
{
id = (unsigned long int) freerdp_map_keyboard_layout_name_to_id(arg->Value);
const int rc = freerdp_map_keyboard_layout_name_to_id(arg->Value);
if (id == -1)
if (rc < 0)
WLog_ERR(TAG, "A problem occurred while mapping the layout name to id");
else if (id == 0)
else if (rc == 0)
{
WLog_ERR(TAG, "Could not identify keyboard layout: %s", arg->Value);
WLog_ERR(TAG, "Use /kbd-list to list available layouts");
}
if (id <= 0)
if (rc <= 0)
return COMMAND_LINE_STATUS_PRINT;
id = rc;
}
settings->KeyboardLayout = (UINT32) id;
}
CommandLineSwitchCase(arg, "kbd-type")
{
settings->KeyboardType = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->KeyboardType = val;
}
CommandLineSwitchCase(arg, "kbd-subtype")
{
settings->KeyboardSubType = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->KeyboardSubType = val;
}
CommandLineSwitchCase(arg, "kbd-fn-key")
{
settings->KeyboardFunctionKey = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->KeyboardFunctionKey = val;
}
CommandLineSwitchCase(arg, "u")
{
@ -1828,8 +1928,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (p)
{
unsigned long val = strtoul(&p[1], NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
length = (int)(p - arg->Value);
settings->GatewayPort = atoi(&p[1]);
settings->GatewayPort = val;
if (!(settings->GatewayHostname = (char*) calloc(length + 1UL, sizeof(char))))
return COMMAND_LINE_ERROR_MEMORY;
@ -1880,15 +1984,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (p)
{
length = (int)(p - arg->Value);
unsigned long val = strtoul(&p[1], NULL, 0);
if (!isdigit(p[1]))
{
WLog_ERR(TAG, "Could not parse proxy port");
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->ProxyPort = atoi(&p[1]);
length = (p - arg->Value);
settings->ProxyPort = val;
settings->ProxyHostname = (char*) malloc(length + 1);
strncpy(settings->ProxyHostname, arg->Value, length);
settings->ProxyHostname[length] = '\0';
@ -1946,9 +2048,11 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "gateway-usage-method")
{
int type;
long type;
char* pEnd;
type = strtol(arg->Value, &pEnd, 10);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (type == 0)
{
@ -2028,7 +2132,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "compression-level")
{
settings->CompressionLevel = atoi(arg->Value);
unsigned long val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->CompressionLevel = val;
}
CommandLineSwitchCase(arg, "drives")
{
@ -2058,8 +2167,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "audio-mode")
{
int mode;
mode = atoi(arg->Value);
long mode = strtol(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (mode == AUDIO_MODE_REDIRECT)
{
@ -2077,9 +2188,11 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "network")
{
int type;
long type;
char* pEnd;
type = strtol(arg->Value, &pEnd, 10);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (type == 0)
{
@ -2144,7 +2257,6 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Value)
{
#ifdef WITH_GFX_H264
if (_strnicmp("AVC444", arg->Value, 6) == 0)
{
settings->GfxH264 = TRUE;
@ -2163,10 +2275,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "gfx-thin-client")
{
settings->GfxThinClient = arg->Value ? TRUE : FALSE;
if (settings->GfxThinClient)
settings->GfxSmallCache = TRUE;
settings->SupportGraphicsPipeline = TRUE;
}
CommandLineSwitchCase(arg, "gfx-small-cache")
@ -2210,7 +2320,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "frame-ack")
{
settings->FrameAcknowledge = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->FrameAcknowledge = val;
}
CommandLineSwitchCase(arg, "nsc")
{
@ -2224,7 +2339,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "jpeg-quality")
{
settings->JpegQuality = atoi(arg->Value) % 100;
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > 100))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->JpegQuality = val;
}
#endif
CommandLineSwitchCase(arg, "nego")
@ -2241,8 +2361,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "pcid")
{
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->SendPreconnectionPdu = TRUE;
settings->PreconnectionId = atoi(arg->Value);
settings->PreconnectionId = val;
}
CommandLineSwitchCase(arg, "sec")
{
@ -2399,7 +2523,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "parent-window")
{
settings->ParentWindowId = strtol(arg->Value, NULL, 0);
UINT64 val = _strtoui64(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->ParentWindowId = val;
}
CommandLineSwitchCase(arg, "bitmap-cache")
{
@ -2426,7 +2555,6 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
settings->NSCodec = TRUE;
}
#if defined(WITH_JPEG)
else if (strcmp(arg->Value, "jpeg") == 0)
{
@ -2435,7 +2563,6 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (settings->JpegQuality == 0)
settings->JpegQuality = 75;
}
#endif
}
CommandLineSwitchCase(arg, "fast-path")
@ -2445,11 +2572,21 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "max-fast-path-size")
{
settings->MultifragMaxRequestSize = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->MultifragMaxRequestSize = val;
}
CommandLineSwitchCase(arg, "max-loop-time")
{
settings->MaxTimeInCheckLoop = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->MaxTimeInCheckLoop = val;
if ((long) settings->MaxTimeInCheckLoop < 0)
{
@ -2504,7 +2641,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "auto-reconnect-max-retries")
{
settings->AutoReconnectMaxRetries = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->AutoReconnectMaxRetries = val;
if (settings->AutoReconnectMaxRetries > 1000)
return COMMAND_LINE_ERROR;
@ -2540,19 +2682,37 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "pwidth")
{
settings->DesktopPhysicalWidth = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->DesktopPhysicalWidth = val;
}
CommandLineSwitchCase(arg, "pheight")
{
settings->DesktopPhysicalHeight = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->DesktopPhysicalHeight = val;
}
CommandLineSwitchCase(arg, "orientation")
{
settings->DesktopOrientation = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > INT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->DesktopOrientation = val;
}
CommandLineSwitchCase(arg, "scale")
{
int scaleFactor = atoi(arg->Value);
unsigned long scaleFactor = strtoul(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (scaleFactor == 100 || scaleFactor == 140 || scaleFactor == 180)
{
@ -2567,7 +2727,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "scale-desktop")
{
int desktopScaleFactor = atoi(arg->Value);
unsigned long desktopScaleFactor = strtoul(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (desktopScaleFactor >= 100 && desktopScaleFactor <= 500)
{
@ -2581,7 +2744,10 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "scale-device")
{
int deviceScaleFactor = atoi(arg->Value);
unsigned long deviceScaleFactor = strtoul(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (deviceScaleFactor == 100 || deviceScaleFactor == 140
|| deviceScaleFactor == 180)
@ -2660,7 +2826,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT)
{
settings->ServerPort = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->ServerPort = val;
}
arg = CommandLineFindArgumentA(args, "p");

View File

@ -23,6 +23,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/cmdline.h>
@ -94,35 +96,59 @@ COMMAND_LINE_ARGUMENT_A old_args[] =
BOOL freerdp_client_old_parse_hostname(char* str, char** ServerHostname, UINT32* ServerPort)
{
char* p;
char* host = NULL;
if (str[0] == '[' && (p = strchr(str, ']'))
&& (p[1] == 0 || (p[1] == ':' && !strchr(p + 2, ':'))))
{
/* Either "[...]" or "[...]:..." with at most one : after the brackets */
if (!(*ServerHostname = _strdup(str + 1)))
if (!(host = _strdup(str + 1)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ']')))
if ((p = strchr(host, ']')))
{
*p = 0;
if (p[1] == ':')
*ServerPort = atoi(p + 2);
{
unsigned long val;
errno = 0;
val = strtoul(p + 2, NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
{
free(host);
return FALSE;
}
*ServerPort = val;
}
}
}
else
{
/* Port number is cut off and used if exactly one : in the string */
if (!(*ServerHostname = _strdup(str)))
if (!(host = _strdup(str)))
return FALSE;
if ((p = strchr((char*) *ServerHostname, ':')) && !strchr(p + 1, ':'))
if ((p = strchr(host, ':')) && !strchr(p + 1, ':'))
{
unsigned long val;
errno = 0;
val = strtoul(p + 1, NULL, 0);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
{
free(host);
return FALSE;
}
*p = 0;
*ServerPort = atoi(p + 1);
*ServerPort = val;
}
}
*ServerHostname = host;
return TRUE;
}
@ -205,7 +231,6 @@ int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args)
return args_handled;
}
int freerdp_client_old_command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv)
{
rdpSettings* settings = (rdpSettings*) context;
@ -374,12 +399,10 @@ int freerdp_client_old_command_line_pre_filter(void* context, int index, int arg
return 0;
}
int freerdp_client_old_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT_A* arg)
{
return 0;
}
int freerdp_detect_old_command_line_syntax(int argc, char** argv, int* count)
{
int status;
@ -445,7 +468,6 @@ int freerdp_detect_old_command_line_syntax(int argc, char** argv, int* count)
free(settings);
return detect_status;
}
int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSettings* settings)
{
char* p;
@ -481,6 +503,7 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
arg = old_args;
errno = 0;
do
{
@ -495,7 +518,12 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "a")
{
settings->ColorDepth = atoi(arg->Value);
unsigned long val = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (val > INT8_MAX))
return FALSE;
settings->ColorDepth = val;
WLog_WARN(TAG, "-a %s -> /bpp:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "c")
@ -538,9 +566,25 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
if (p)
{
unsigned long h, w = strtoul(str, NULL, 0);
if ((errno != 0) || (w == 0) || (w > UINT16_MAX))
{
free(str);
return FALSE;
}
h = strtoul(&p[1], NULL, 0);
if ((errno != 0) || (h == 0) || (h > UINT16_MAX))
{
free(str);
return FALSE;
}
*p = '\0';
settings->DesktopWidth = atoi(str);
settings->DesktopHeight = atoi(&p[1]);
settings->DesktopWidth = w;
settings->DesktopHeight = h;
}
free(str);
@ -587,7 +631,12 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "t")
{
settings->ServerPort = atoi(arg->Value);
unsigned long p = strtoul(arg->Value, NULL, 0);
if ((errno != 0) || (p == 0) || (p > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
settings->ServerPort = p;
WLog_WARN(TAG, "-t %s -> /port:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "u")
@ -599,10 +648,13 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "x")
{
int type;
long type;
char* pEnd;
type = strtol(arg->Value, &pEnd, 16);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if (type == 0)
{
type = CONNECTION_TYPE_LAN;
@ -635,7 +687,11 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe
}
CommandLineSwitchCase(arg, "X")
{
settings->ParentWindowId = strtol(arg->Value, NULL, 0);
settings->ParentWindowId = _strtoui64(arg->Value, NULL, 0);
if (errno != 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
WLog_WARN(TAG, "-X %s -> /parent-window:%s", arg->Value, arg->Value);
}
CommandLineSwitchCase(arg, "z")

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <freerdp/client/file.h>
#include <freerdp/client/cmdline.h>
@ -222,7 +224,7 @@ static BOOL freerdp_client_parse_rdp_file_integer_unicode(rdpFile* file, const W
const WCHAR* value, int index)
{
int length;
int ivalue;
long ivalue;
char* nameA;
char* valueA;
BOOL ret = TRUE;
@ -245,9 +247,12 @@ static BOOL freerdp_client_parse_rdp_file_integer_unicode(rdpFile* file, const W
WideCharToMultiByte(CP_UTF8, 0, value, length, valueA, length, NULL, NULL);
valueA[length] = '\0';
ivalue = atoi(valueA);
errno = 0;
ivalue = strtol(valueA, NULL, 0);
if (freerdp_client_rdp_file_set_integer(file, nameA, ivalue, index) < 0)
if ((errno != 0) || (ivalue < INT32_MIN) || (ivalue > INT32_MAX))
ret = FALSE;
else if (freerdp_client_rdp_file_set_integer(file, nameA, ivalue, index) < 0)
ret = FALSE;
free(nameA);
@ -258,7 +263,12 @@ static BOOL freerdp_client_parse_rdp_file_integer_unicode(rdpFile* file, const W
static BOOL freerdp_client_parse_rdp_file_integer_ascii(rdpFile* file, const char* name,
const char* value, int index)
{
int ivalue = atoi(value);
long ivalue;
errno = 0;
ivalue = strtol(value, NULL, 0);
if ((errno != 0) || (ivalue < INT32_MIN) || (ivalue > INT32_MAX))
return FALSE;
if (freerdp_client_rdp_file_set_integer(file, name, ivalue, index) < 0)
return FALSE;

View File

@ -21,6 +21,8 @@
#import "RDPSession.h"
#import "Utils.h"
#include <errno.h>
#define TAG FREERDP_TAG("iOS")
#pragma mark Connection helpers

View File

@ -2964,7 +2964,6 @@ static BOOL RunTestPlanar(BITMAP_PLANAR_CONTEXT* planar, const BYTE* srcBitmap,
const UINT32 width, const UINT32 height)
{
BOOL rc = FALSE;
const UINT32 size = width * height * GetBytesPerPixel(dstFormat);
UINT32 dstSize;
BYTE* compressedBitmap = freerdp_bitmap_compress_planar(planar,
srcBitmap, srcFormat, width, height, 0, NULL, &dstSize);

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/wtypes.h>
#include <winpr/crt.h>
#include <winpr/crypto.h>
@ -78,7 +80,6 @@ int freerdp_assistance_crypt_derive_key_sha1(BYTE* hash, int hashLength, BYTE* k
BYTE* buffer;
BYTE pad1[64];
BYTE pad2[64];
memset(pad1, 0x36, 64);
memset(pad2, 0x5C, 64);
@ -100,11 +101,9 @@ int freerdp_assistance_crypt_derive_key_sha1(BYTE* hash, int hashLength, BYTE* k
goto fail;
CopyMemory(key, buffer, keyLength);
rc = 1;
fail:
free(buffer);
return rc;
}
@ -117,7 +116,6 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
int count;
int length;
char** tokens;
count = 1;
str = _strdup(list);
@ -133,6 +131,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
}
tokens = (char**) calloc(count, sizeof(char*));
if (!tokens)
{
free(str);
@ -161,7 +160,6 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
for (i = 0; i < count; i++)
{
p = tokens[i];
q = strchr(p, ':');
if (!q)
@ -169,9 +167,16 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
q[0] = '\0';
q++;
file->MachineAddresses[i] = _strdup(p);
file->MachinePorts[i] = (UINT32) atoi(q);
errno = 0;
{
unsigned long val = strtoul(q, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
goto out;
file->MachinePorts[i] = val;
}
if (!file->MachineAddresses[i])
goto out;
@ -190,7 +195,6 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
}
p = tokens[i];
q = strchr(p, ':');
if (!q)
@ -201,10 +205,21 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
if (file->MachineAddress)
free(file->MachineAddress);
file->MachineAddress = _strdup(p);
if (!file->MachineAddress)
goto out;
file->MachinePort = (UINT32) atoi(q);
errno = 0;
{
unsigned long val = strtoul(q, NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
goto out;
file->MachinePort = val;
}
if (!file->MachineAddress)
goto out;
@ -216,18 +231,18 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
free(str);
return 1;
out:
if (file->MachineAddresses)
{
for (i=0; i<count; i++)
free (file->MachineAddresses[i]);
for (i = 0; i < count; i++)
free(file->MachineAddresses[i]);
}
free (file->MachineAddresses);
free (file->MachinePorts);
free(file->MachineAddresses);
free(file->MachinePorts);
file->MachineCount = 0;
file->MachinePorts = NULL;
file->MachineAddresses = NULL;
free(tokens);
free(str);
return -1;
@ -241,12 +256,10 @@ int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
int length;
char* tokens[8];
int ret = -1;
/**
* <ProtocolVersion>,<protocolType>,<machineAddressList>,<assistantAccountPwd>,
* <RASessionID>,<RASessionName>,<RASessionPwd>,<protocolSpecificParms>
*/
count = 1;
str = _strdup(file->RCTicket);
@ -302,7 +315,6 @@ int freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
goto error;
ret = freerdp_assistance_parse_address_list(file, tokens[2]);
error:
free(str);
@ -335,8 +347,6 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
char* end;
char* p;
int ret = -1;
str = file->ConnectionString2;
if (!strstr(str, "<E>"))
@ -346,6 +356,7 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
return -1;
str = _strdup(file->ConnectionString2);
if (!str)
return -1;
@ -354,15 +365,16 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
/* Parse Auth String Node (<A>) */
end = strstr(tag, "/>");
if (!end)
goto out_fail;
*end = '\0';
p = strstr(tag, "KH=\"");
if (p)
{
char *q;
char* q;
size_t length;
p += sizeof("KH=\"") - 1;
q = strchr(p, '"');
@ -373,6 +385,7 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
length = q - p;
free(file->RASpecificParams);
file->RASpecificParams = (char*) malloc(length + 1);
if (!file->RASpecificParams)
goto out_fail;
@ -381,9 +394,10 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
}
p = strstr(tag, "ID=\"");
if (p)
{
char *q;
char* q;
size_t length;
p += sizeof("ID=\"") - 1;
q = strchr(p, '"');
@ -394,24 +408,24 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
length = q - p;
free(file->RASessionId);
file->RASessionId = (char*) malloc(length + 1);
if (!file->RASessionId)
goto out_fail;
CopyMemory(file->RASessionId, p, length);
file->RASessionId[length] = '\0';
}
*end = '/';
/* Parse <L last address is used */
p = strstr(str, "<L P=\"");
while (p)
{
char *q;
char* q;
int port;
size_t length;
p += sizeof("<L P=\"") - 1;
q = strchr(p, '"');
if (!q)
@ -419,16 +433,21 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
q[0] = '\0';
q++;
errno = 0;
{
unsigned long val = strtoul(p, NULL, 0);
port = atoi(p);
if ((errno != 0) || (val == 0) || (val > UINT16_MAX))
goto out_fail;
port = val;
}
p = strstr(q, " N=\"");
if (!p)
goto out_fail;
p += sizeof(" N=\"") - 1;
q = strchr(p, '"');
if (!q)
@ -436,7 +455,6 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
q[0] = '\0';
q++;
length = strlen(p);
if (length > 8)
@ -445,9 +463,12 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
{
if (file->MachineAddress)
free(file->MachineAddress);
file->MachineAddress = _strdup(p);
if (!file->MachineAddress)
goto out_fail;
file->MachinePort = (UINT32) port;
break;
}
@ -460,7 +481,6 @@ int freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
out_fail:
free(str);
return ret;
}
char* freerdp_assistance_construct_expert_blob(const char* name, const char* pass)
@ -475,7 +495,6 @@ char* freerdp_assistance_construct_expert_blob(const char* name, const char* pas
nameLength = strlen(name) + strlen("NAME=");
passLength = strlen(pass) + strlen("PASS=");
size = nameLength + passLength + 64;
ExpertBlob = (char*) calloc(1, size);
@ -483,8 +502,7 @@ char* freerdp_assistance_construct_expert_blob(const char* name, const char* pas
return NULL;
sprintf_s(ExpertBlob, size, "%d;NAME=%s%d;PASS=%s",
nameLength, name, passLength, pass);
nameLength, name, passLength, pass);
return ExpertBlob;
}
@ -497,7 +515,6 @@ char* freerdp_assistance_generate_pass_stub(DWORD flags)
char set3[10] = "0123456789";
char set4[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char set5[26] = "abcdefghijklmnopqrstuvwxyz";
passStub = (char*) malloc(15);
if (!passStub)
@ -514,9 +531,7 @@ char* freerdp_assistance_generate_pass_stub(DWORD flags)
*
* Example: WB^6HsrIaFmEpi
*/
winpr_RAND((BYTE*) nums, sizeof(nums));
passStub[0] = set1[nums[0] % sizeof(set1)]; /* character 0 */
passStub[1] = set2[nums[1] % sizeof(set2)]; /* character 1 */
passStub[2] = set3[nums[2] % sizeof(set3)]; /* character 2 */
@ -532,11 +547,11 @@ char* freerdp_assistance_generate_pass_stub(DWORD flags)
passStub[12] = set1[nums[12] % sizeof(set1)]; /* character 12 */
passStub[13] = set1[nums[13] % sizeof(set1)]; /* character 13 */
passStub[14] = '\0';
return passStub;
}
BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* passStub, int* pEncryptedSize)
BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* passStub,
int* pEncryptedSize)
{
BOOL rc;
int status;
@ -549,7 +564,6 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
size_t cbOut, cbIn, cbFinal;
WCHAR* PasswordW = NULL;
WCHAR* PassStubW = NULL;
status = ConvertToUnicode(CP_UTF8, 0, password, -1, &PasswordW, 0);
if (status <= 0)
@ -557,9 +571,10 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
cbPasswordW = (status - 1) * 2;
if (!winpr_Digest(WINPR_MD_MD5, (BYTE*)PasswordW, cbPasswordW, (BYTE*) PasswordHash, sizeof(PasswordHash)))
if (!winpr_Digest(WINPR_MD_MD5, (BYTE*)PasswordW, cbPasswordW, (BYTE*) PasswordHash,
sizeof(PasswordHash)))
{
free (PasswordW);
free(PasswordW);
return NULL;
}
@ -567,14 +582,12 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
if (status <= 0)
{
free (PasswordW);
free(PasswordW);
return NULL;
}
cbPassStubW = (status - 1) * 2;
EncryptedSize = cbPassStubW + 4;
pbIn = (BYTE*) calloc(1, EncryptedSize);
pbOut = (BYTE*) calloc(1, EncryptedSize);
@ -598,23 +611,21 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
*((UINT32*) pbIn) = cbPassStubW;
CopyMemory(&pbIn[4], PassStubW, cbPassStubW);
free(PasswordW);
free(PassStubW);
rc4Ctx = winpr_Cipher_New(WINPR_CIPHER_ARC4_128, WINPR_ENCRYPT,
PasswordHash, NULL);
PasswordHash, NULL);
if (!rc4Ctx)
{
WLog_ERR(TAG, "EVP_CipherInit_ex failure");
free (pbOut);
free (pbIn);
free(pbOut);
free(pbIn);
return NULL;
}
cbOut = cbFinal = 0;
cbIn = EncryptedSize;
rc = winpr_Cipher_Update(rc4Ctx, pbIn, cbIn, pbOut, &cbOut);
free(pbIn);
@ -622,7 +633,7 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
{
WLog_ERR(TAG, "EVP_CipherUpdate failure");
winpr_Cipher_Free(rc4Ctx);
free (pbOut);
free(pbOut);
return NULL;
}
@ -630,14 +641,12 @@ BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* pas
{
WLog_ERR(TAG, "EVP_CipherFinal_ex failure");
winpr_Cipher_Free(rc4Ctx);
free (pbOut);
free(pbOut);
return NULL;
}
winpr_Cipher_Free(rc4Ctx);
*pEncryptedSize = EncryptedSize;
return pbOut;
}
@ -654,7 +663,6 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
BYTE DerivedKey[WINPR_AES_BLOCK_SIZE];
BYTE InitializationVector[WINPR_AES_BLOCK_SIZE];
BYTE PasswordHash[WINPR_SHA1_DIGEST_LENGTH];
status = ConvertToUnicode(CP_UTF8, 0, password, -1, &PasswordW, 0);
if (status <= 0)
@ -664,12 +672,12 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
if (!winpr_Digest(WINPR_MD_SHA1, (BYTE*)PasswordW, cbPasswordW, PasswordHash, sizeof(PasswordHash)))
{
free (PasswordW);
free(PasswordW);
return -1;
}
status = freerdp_assistance_crypt_derive_key_sha1(PasswordHash, sizeof(PasswordHash),
DerivedKey, sizeof(DerivedKey));
DerivedKey, sizeof(DerivedKey));
if (status < 0)
{
@ -678,9 +686,9 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
}
ZeroMemory(InitializationVector, sizeof(InitializationVector));
aesDec = winpr_Cipher_New(WINPR_CIPHER_AES_128_CBC, WINPR_DECRYPT,
DerivedKey, InitializationVector);
DerivedKey, InitializationVector);
if (!aesDec)
{
free(PasswordW);
@ -717,16 +725,12 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
}
winpr_Cipher_Free(aesDec);
cbOut += cbFinal;
cbFinal = 0;
pbOutW = (WCHAR*) pbOut;
cchOutW = cbOut / 2;
file->ConnectionString2 = NULL;
status = ConvertFromUnicode(CP_UTF8, 0, pbOutW, cchOutW, &file->ConnectionString2, 0, NULL, NULL);
free(PasswordW);
free(pbOut);
@ -743,9 +747,8 @@ int freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
int freerdp_assistance_decrypt(rdpAssistanceFile* file, const char* password)
{
int status = 1;
file->EncryptedPassStub = freerdp_assistance_encrypt_pass_stub(password,
file->PassStub, &file->EncryptedPassStubLength);
file->PassStub, &file->EncryptedPassStubLength);
if (!file->EncryptedPassStub)
return -1;
@ -764,7 +767,6 @@ BYTE* freerdp_assistance_hex_string_to_bin(const char* str, int* size)
int length;
BYTE* buffer;
int i, ln, hn;
length = strlen(str);
if ((length % 2) != 0)
@ -772,7 +774,6 @@ BYTE* freerdp_assistance_hex_string_to_bin(const char* str, int* size)
length /= 2;
*size = length;
buffer = (BYTE*) malloc(length);
if (!buffer)
@ -781,7 +782,6 @@ BYTE* freerdp_assistance_hex_string_to_bin(const char* str, int* size)
for (i = 0; i < length; i++)
{
hn = ln = 0;
c = str[(i * 2) + 0];
if ((c >= '0') && (c <= '9'))
@ -812,8 +812,8 @@ char* freerdp_assistance_bin_to_hex_string(const BYTE* data, int size)
char* p;
int ln, hn;
char bin2hex[] = "0123456789ABCDEF";
p = (char*) calloc((size + 1), 2);
if (!p)
return NULL;
@ -821,13 +821,11 @@ char* freerdp_assistance_bin_to_hex_string(const BYTE* data, int size)
{
ln = data[i] & 0xF;
hn = (data[i] >> 4) & 0xF;
p[i * 2] = bin2hex[hn];
p[(i * 2) + 1] = bin2hex[ln];
}
p[size * 2] = '\0';
return p;
}
@ -836,10 +834,8 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
char* p;
char* q;
char* r;
int value;
int status;
size_t length;
p = strstr(buffer, "UPLOADINFO");
if (!p)
@ -856,7 +852,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
return -1;
/* Parse USERNAME */
p = strstr(buffer, "USERNAME=\"");
if (p)
@ -878,7 +873,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
}
/* Parse LHTICKET */
p = strstr(buffer, "LHTICKET=\"");
if (p)
@ -900,7 +894,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
}
/* Parse RCTICKET */
p = strstr(buffer, "RCTICKET=\"");
if (p)
@ -922,7 +915,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
}
/* Parse RCTICKETENCRYPTED */
p = strstr(buffer, "RCTICKETENCRYPTED=\"");
if (p)
@ -940,7 +932,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
}
/* Parse PassStub */
p = strstr(buffer, "PassStub=\"");
if (p)
@ -962,7 +953,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
}
/* Parse DtStart */
p = strstr(buffer, "DtStart=\"");
if (p)
@ -974,7 +964,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
return -1;
length = q - p;
r = (char*) malloc(length + 1);
if (!r)
@ -982,18 +971,19 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
CopyMemory(r, p, length);
r[length] = '\0';
errno = 0;
{
unsigned long val = strtoul(r, NULL, 0);
free(r);
value = atoi(r);
free(r);
if ((errno != 0) || (val > UINT32_MAX))
return -1;
if (value < 0)
return -1;
file->DtStart = (UINT32) value;
file->DtStart = val;
}
}
/* Parse DtLength */
p = strstr(buffer, "DtLength=\"");
if (p)
@ -1005,7 +995,6 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
return -1;
length = q - p;
r = (char*) malloc(length + 1);
if (!r)
@ -1013,18 +1002,19 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
CopyMemory(r, p, length);
r[length] = '\0';
errno = 0;
{
unsigned long val = strtoul(r, NULL, 0);
free(r);
value = atoi(r);
free(r);
if ((errno != 0) || (val > UINT32_MAX))
return -1;
if (value < 0)
return -1;
file->DtLength = (UINT32) value;
file->DtLength = val;
}
}
/* Parse L (LowSpeed) */
p = strstr(buffer, " L=\"");
if (p)
@ -1046,7 +1036,7 @@ int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* bu
if (file->LHTicket)
{
file->EncryptedLHTicket = freerdp_assistance_hex_string_to_bin(file->LHTicket,
&file->EncryptedLHTicketLength);
&file->EncryptedLHTicketLength);
}
status = freerdp_assistance_parse_connection_string1(file);
@ -1067,7 +1057,6 @@ int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name)
FILE* fp = NULL;
size_t readSize;
INT64 fileSize;
fp = fopen(name, "r");
if (!fp)
@ -1098,6 +1087,7 @@ int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name)
if (!ferror(fp))
readSize = fileSize;
}
fclose(fp);
if (readSize < 1)
@ -1109,18 +1099,15 @@ int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name)
buffer[fileSize] = '\0';
buffer[fileSize + 1] = '\0';
status = freerdp_assistance_parse_file_buffer(file, (char*) buffer, fileSize);
free(buffer);
return status;
}
int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* file, rdpSettings* settings)
int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* file,
rdpSettings* settings)
{
UINT32 i;
freerdp_set_param_bool(settings, FreeRDP_RemoteAssistanceMode, TRUE);
if (!file->RASessionId || !file->MachineAddress)
@ -1129,19 +1116,19 @@ int freerdp_client_populate_settings_from_assistance_file(rdpAssistanceFile* fil
if (freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceSessionId, file->RASessionId) != 0)
return -1;
if (file->RCTicket && (freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceRCTicket, file->RCTicket) != 0))
if (file->RCTicket &&
(freerdp_set_param_string(settings, FreeRDP_RemoteAssistanceRCTicket, file->RCTicket) != 0))
return -1;
if (file->PassStub && (freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub) != 0))
if (file->PassStub &&
(freerdp_set_param_string(settings, FreeRDP_RemoteAssistancePassStub, file->PassStub) != 0))
return -1;
if (freerdp_set_param_string(settings, FreeRDP_ServerHostname, file->MachineAddress) != 0)
return -1;
freerdp_set_param_uint32(settings, FreeRDP_ServerPort, file->MachinePort);
freerdp_target_net_addresses_free(settings);
settings->TargetNetAddressCount = file->MachineCount;
if (settings->TargetNetAddressCount)
@ -1196,6 +1183,5 @@ void freerdp_assistance_file_free(rdpAssistanceFile* file)
free(file->MachineAddresses);
free(file->MachinePorts);
free(file);
}

View File

@ -21,6 +21,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/print.h>
#include <winpr/stream.h>
@ -52,12 +54,12 @@ static char* string_strnstr(const char* str1, const char* str2, size_t slen)
if (slen-- < 1 || (sc = *str1++) == '\0')
return NULL;
}
while(sc != c);
while (sc != c);
if (len > slen)
return NULL;
}
while(strncmp(str1, str2, len) != 0);
while (strncmp(str1, str2, len) != 0);
str1--;
}
@ -258,7 +260,6 @@ char* http_encode_body_line(char* param, char* value)
{
char* line;
int length;
length = strlen(param) + strlen(value) + 2;
line = (char*) malloc(length + 1);
@ -274,7 +275,6 @@ char* http_encode_content_length_line(int ContentLength)
char* line;
int length;
char str[32];
_itoa_s(ContentLength, str, sizeof(str), 10);
length = strlen("Content-Length") + strlen(str) + 2;
line = (char*) malloc(length + 1);
@ -290,7 +290,6 @@ char* http_encode_header_line(char* Method, char* URI)
{
char* line;
int length;
length = strlen("HTTP/1.1") + strlen(Method) + strlen(URI) + 2;
line = (char*)malloc(length + 1);
@ -305,7 +304,6 @@ char* http_encode_authorization_line(char* AuthScheme, char* AuthParam)
{
char* line;
int length;
length = strlen("Authorization") + strlen(AuthScheme) + strlen(AuthParam) + 3;
line = (char*) malloc(length + 1);
@ -322,7 +320,6 @@ wStream* http_request_write(HttpContext* context, HttpRequest* request)
int i, count;
char** lines;
int length = 0;
count = 0;
lines = (char**) calloc(32, sizeof(char*));
@ -409,8 +406,8 @@ wStream* http_request_write(HttpContext* context, HttpRequest* request)
Stream_Rewind(s, 1); /* don't include null terminator in length */
Stream_SetLength(s, Stream_GetPosition(s));
return s;
out_free:
for (i = 0; i < count; i++)
free(lines[i]);
@ -458,7 +455,15 @@ BOOL http_response_parse_header_status_line(HttpResponse* response, char* status
reason_phrase = separator + 1;
*separator = '\0';
response->StatusCode = atoi(status_code);
errno = 0;
{
long val = strtol(status_code, NULL, 0);
if ((errno != 0) || (val < 0) || (val > INT16_MAX))
return FALSE;
response->StatusCode = strtol(status_code, NULL, 0);
}
response->ReasonPhrase = _strdup(reason_phrase);
if (!response->ReasonPhrase)
@ -474,7 +479,14 @@ BOOL http_response_parse_header_field(HttpResponse* response, char* name, char*
if (_stricmp(name, "Content-Length") == 0)
{
response->ContentLength = atoi(value);
long val;
errno = 0;
val = strtol(value, NULL, 0);
if ((errno != 0) || (val < 0) || (val > INT32_MAX))
return FALSE;
response->ContentLength = val;
}
else if (_stricmp(name, "Content-Type") == 0)
{
@ -488,7 +500,6 @@ BOOL http_response_parse_header_field(HttpResponse* response, char* name, char*
char* separator = NULL;
char* authScheme = NULL;
char* authValue = NULL;
separator = strchr(value, ' ');
if (separator)
@ -551,6 +562,7 @@ BOOL http_response_parse_header(HttpResponse* response)
for (count = 1; count < response->count; count++)
{
line = response->lines[count];
/**
* name end_of_header
* | |
@ -624,18 +636,15 @@ HttpResponse* http_response_recv(rdpTls* tls)
int bodyLength;
int payloadOffset;
HttpResponse* response;
size = 2048;
payload = NULL;
payloadOffset = 0;
s = Stream_New(NULL, size);
if (!s)
goto out_free;
buffer = (char*) Stream_Buffer(s);
response = http_response_new();
if (!response)
@ -661,13 +670,13 @@ HttpResponse* http_response_recv(rdpTls* tls)
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(Stream_Pointer(s), status);
#endif
Stream_Seek(s, status);
if (Stream_GetRemainingLength(s) < 1024)
{
if (!Stream_EnsureRemainingCapacity(s, 1024))
goto out_error;
buffer = (char*) Stream_Buffer(s);
payload = &buffer[payloadOffset];
}
@ -690,7 +699,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
{
count = 0;
line = buffer;
position = Stream_GetPosition(s);
while ((line = string_strnstr(line, "\r\n", payloadOffset - (line - buffer) - 2)))
@ -717,7 +725,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
CopyMemory(header, buffer, payloadOffset);
header[payloadOffset - 1] = '\0';
header[payloadOffset - 2] = '\0';
count = 0;
line = strtok(header, "\r\n");
@ -736,7 +743,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
goto out_error;
response->BodyLength = Stream_GetPosition(s) - payloadOffset;
bodyLength = 0; /* expected body length */
if (response->ContentType)
@ -772,7 +778,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
Stream_Seek(s, status);
response->BodyLength += status;
}
if (response->BodyLength > 0)
@ -789,7 +794,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
if (bodyLength != response->BodyLength)
{
WLog_WARN(TAG, "http_response_recv: %s unexpected body length: actual: %d, expected: %d",
response->ContentType, bodyLength, response->BodyLength);
response->ContentType, bodyLength, response->BodyLength);
}
break;
@ -799,6 +804,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
{
if (!Stream_EnsureRemainingCapacity(s, 1024))
goto out_error;
buffer = (char*) Stream_Buffer(s);
payload = &buffer[payloadOffset];
}
@ -823,6 +829,7 @@ HttpResponse* http_response_new()
return NULL;
response->Authenticates = ListDictionary_New(FALSE);
if (!response->Authenticates)
{
free(response);
@ -831,10 +838,8 @@ HttpResponse* http_response_new()
ListDictionary_KeyObject(response->Authenticates)->fnObjectEquals = strings_equals_nocase;
ListDictionary_KeyObject(response->Authenticates)->fnObjectFree = string_free;
ListDictionary_ValueObject(response->Authenticates)->fnObjectEquals = strings_equals_nocase;
ListDictionary_ValueObject(response->Authenticates)->fnObjectFree = string_free;
return response;
}
@ -851,9 +856,7 @@ void http_response_free(HttpResponse* response)
free(response->lines);
free(response->ReasonPhrase);
free(response->ContentType);
ListDictionary_Free(response->Authenticates);
if (response->BodyContent)

View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/windows.h>
@ -63,7 +64,6 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
#ifdef _WIN32
u_long arg;
#endif
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@ -108,7 +108,6 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
sin_addr = &(((struct sockaddr_in6*) ai->ai_addr)->sin6_addr);
inet_ntop(ai->ai_family, sin_addr, addr, sizeof(addr));
option_value = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &option_value, sizeof(option_value)) == -1)
@ -120,7 +119,6 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
arg = 1;
ioctlsocket(sockfd, FIONBIO, &arg);
#endif
status = _bind((SOCKET) sockfd, ai->ai_addr, ai->ai_addrlen);
if (status != 0)
@ -139,22 +137,21 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
}
/* FIXME: these file descriptors do not work on Windows */
listener->sockfds[listener->num_sockfds] = sockfd;
listener->events[listener->num_sockfds] = WSACreateEvent();
if (!listener->events[listener->num_sockfds])
{
listener->num_sockfds = 0;
break;
}
WSAEventSelect(sockfd, listener->events[listener->num_sockfds], FD_READ | FD_ACCEPT | FD_CLOSE);
listener->num_sockfds++;
WLog_INFO(TAG, "Listening on %s:%s", addr, servname);
}
freeaddrinfo(res);
return (listener->num_sockfds > 0 ? TRUE : FALSE);
}
@ -182,10 +179,8 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char*
}
fcntl(sockfd, F_SETFL, O_NONBLOCK);
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
unlink(path);
status = _bind(sockfd, (struct sockaddr*) &addr, sizeof(addr));
@ -206,6 +201,7 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char*
}
hevent = CreateFileDescriptorEvent(NULL, FALSE, FALSE, sockfd, WINPR_FD_READ);
if (!hevent)
{
WLog_ERR(TAG, "failed to create sockfd event");
@ -239,25 +235,22 @@ static BOOL freerdp_listener_open_from_socket(freerdp_listener* instance, int fd
listener->sockfds[listener->num_sockfds] = fd;
listener->events[listener->num_sockfds] =
CreateFileDescriptorEvent(NULL, FALSE, FALSE, fd, WINPR_FD_READ);
CreateFileDescriptorEvent(NULL, FALSE, FALSE, fd, WINPR_FD_READ);
if (!listener->events[listener->num_sockfds])
return FALSE;
listener->num_sockfds++;
WLog_INFO(TAG, "Listening on socket %d.", fd);
return TRUE;
#else
return FALSE;
#endif
}
static void freerdp_listener_close(freerdp_listener* instance)
{
int i;
rdpListener* listener = (rdpListener*) instance->listener;
for (i = 0; i < listener->num_sockfds; i++)
@ -323,7 +316,6 @@ static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
for (i = 0; i < listener->num_sockfds; i++)
{
WSAResetEvent(listener->events[i]);
peer_addr_size = sizeof(peer_addr);
peer_sockfd = _accept(listener->sockfds[i], (struct sockaddr*) &peer_addr, &peer_addr_size);
peer_accepted = FALSE;
@ -336,17 +328,20 @@ static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
/* No data available */
if (wsa_error == WSAEWOULDBLOCK)
continue;
#else
if (errno == EAGAIN || errno == EWOULDBLOCK)
continue;
#endif
WLog_DBG(TAG, "accept");
free(client);
return FALSE;
}
client = freerdp_peer_new(peer_sockfd);
if (!client)
{
closesocket((SOCKET) peer_sockfd);
@ -354,21 +349,26 @@ static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
}
sin_addr = NULL;
if (peer_addr.ss_family == AF_INET)
{
sin_addr = &(((struct sockaddr_in*) &peer_addr)->sin_addr);
if ((*(UINT32*) sin_addr) == 0x0100007f)
client->local = TRUE;
}
else if (peer_addr.ss_family == AF_INET6)
{
sin_addr = &(((struct sockaddr_in6*) &peer_addr)->sin6_addr);
if (memcmp(sin_addr, localhost6_bytes, 16) == 0)
client->local = TRUE;
}
#ifndef _WIN32
else if (peer_addr.ss_family == AF_UNIX)
client->local = TRUE;
#endif
if (sin_addr)
@ -391,7 +391,6 @@ freerdp_listener* freerdp_listener_new(void)
{
freerdp_listener* instance;
rdpListener* listener;
instance = (freerdp_listener*) calloc(1, sizeof(freerdp_listener));
if (!instance)
@ -404,25 +403,21 @@ freerdp_listener* freerdp_listener_new(void)
instance->GetEventHandles = freerdp_listener_get_event_handles;
instance->CheckFileDescriptor = freerdp_listener_check_fds;
instance->Close = freerdp_listener_close;
listener = (rdpListener*) calloc(1, sizeof(rdpListener));
if (!listener)
{
free (instance);
free(instance);
return NULL;
}
listener->instance = instance;
instance->listener = (void*) listener;
return instance;
}
void freerdp_listener_free(freerdp_listener* instance)
{
if (instance)
{
free(instance->listener);

View File

@ -18,6 +18,7 @@
*/
#include <ctype.h>
#include <errno.h>
#include "proxy.h"
#include "freerdp/settings.h"
@ -109,13 +110,14 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
if (pport)
{
if (!isdigit(*(pport + 1)))
{
WLog_ERR(TAG, "Could not parse proxy port");
return FALSE;
}
long val;
errno = 0;
val = strtol(pport + 1, NULL, 0);
port = atoi(pport + 1);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
return FALSE;
port = val;
}
else
{

View File

@ -23,6 +23,7 @@
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/sspi.h>
@ -234,7 +235,6 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
int status = -1;
BIO_RDP_TLS* tls = (BIO_RDP_TLS*) BIO_get_data(bio);
if (!tls)
return 0;
@ -340,6 +340,7 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
break;
case BIO_CTRL_POP:
/* Only detach if we are the BIO explicitly being popped */
if (bio == ptr)
{
@ -347,8 +348,10 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
BIO_free_all(ssl_wbio);
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (next_bio)
CRYPTO_add(&(bio->next_bio->references), -1, CRYPTO_LOCK_BIO);
tls->ssl->wbio = tls->ssl->rbio = NULL;
#else
/* OpenSSL 1.1: This will also clear the reference we obtained during push */
@ -392,7 +395,6 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
}
BIO_set_init(bio, 1);
status = 1;
break;
@ -437,16 +439,13 @@ static long bio_rdp_tls_ctrl(BIO* bio, int cmd, long num, void* ptr)
static int bio_rdp_tls_new(BIO* bio)
{
BIO_RDP_TLS* tls;
BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY);
if (!(tls = calloc(1, sizeof(BIO_RDP_TLS))))
return 0;
InitializeCriticalSectionAndSpinCount(&tls->lock, 4000);
BIO_set_data(bio, (void*) tls);
return 1;
}
@ -469,6 +468,7 @@ static int bio_rdp_tls_free(BIO* bio)
SSL_shutdown(tls->ssl);
SSL_free(tls->ssl);
}
BIO_set_init(bio, 0);
BIO_set_flags(bio, 0);
}
@ -1016,12 +1016,12 @@ BOOL tls_send_alert(rdpTls* tls)
if (!tls->ssl)
return TRUE;
/**
* FIXME: The following code does not work on OpenSSL > 1.1.0 because the
* SSL struct is opaqe now
*/
/**
* FIXME: The following code does not work on OpenSSL > 1.1.0 because the
* SSL struct is opaqe now
*/
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
if (tls->alertDescription != TLS_ALERT_DESCRIPTION_CLOSE_NOTIFY)
{
/**
@ -1035,7 +1035,6 @@ BOOL tls_send_alert(rdpTls* tls)
*/
SSL_SESSION* ssl_session = SSL_get_session(tls->ssl);
SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(tls->ssl);
SSL_set_quiet_shutdown(tls->ssl, 1);
if ((tls->alertLevel == TLS_ALERT_LEVEL_FATAL) && (ssl_session))
@ -1048,8 +1047,8 @@ BOOL tls_send_alert(rdpTls* tls)
if (tls->ssl->s3->wbuf.left == 0)
tls->ssl->method->ssl_dispatch_alert(tls->ssl);
}
#endif
#endif
return TRUE;
}

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <winpr/crt.h>
@ -210,8 +211,8 @@ int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
char* pch;
char* beg;
char* end;
int rc = -1;
char buffer[1024];
/*
Sample output for "kbd -t -l" :
@ -221,10 +222,8 @@ int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
delay(ms)=500
rate(ms)=40
*/
*type = 0;
*layout = 0;
kbd = popen("kbd -t -l", "r");
if (!kbd)
@ -232,25 +231,40 @@ int freerdp_get_solaris_keyboard_layout_and_type(int* type, int* layout)
while (fgets(buffer, sizeof(buffer), kbd) != NULL)
{
long val;
if ((pch = strstr(buffer, "type=")) != NULL)
{
beg = pch + sizeof("type=") - 1;
end = strchr(beg, '\n');
end[0] = '\0';
*type = atoi(beg);
errno = 0;
val = strtol(beg, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
goto fail;
*type = val;
}
else if ((pch = strstr(buffer, "layout=")) != NULL)
{
beg = pch + sizeof("layout=") - 1;
end = strchr(beg, ' ');
end[0] = '\0';
*layout = atoi(beg);
errno = 0;
val = strtol(beg, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
goto fail;
*layout = val;
}
}
rc = 0;
fail:
pclose(kbd);
return 0;
return rc;
}
DWORD freerdp_detect_solaris_keyboard_layout()

View File

@ -20,6 +20,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/wtypes.h>
#include <winpr/crt.h>
#include <winpr/path.h>
@ -274,7 +276,15 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
return -1;
*q = '\0';
font->size = atoi(p);
errno = 0;
{
long val = strtol(p, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
font->size = val;
}
*q = '"';
if (font->size <= 0)
@ -314,7 +324,15 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
return -1;
*q = '\0';
font->height = atoi(p);
errno = 0;
{
long val = strtol(p, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
font->height = val;
}
*q = '"';
if (font->height <= 0)
@ -406,7 +424,15 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
return -1;
*q = '\0';
glyph->width = atoi(p);
errno = 0;
{
long val = strtoul(p, NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->width = val;
}
*q = '"';
if (glyph->width < 0)
@ -434,8 +460,23 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
*p = 0;
tok[1] = p + 1;
glyph->offsetX = atoi(tok[0]);
glyph->offsetY = atoi(tok[1]);
errno = 0;
{
long val = strtol(tok[0], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->offsetX = val;
}
{
long val = strtol(tok[1], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->offsetY = val;
}
*q = '"';
p = q + 1;
/* parse glyph rect x,y,w,h */
@ -473,10 +514,39 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
*p = 0;
tok[3] = p + 1;
glyph->rectX = atoi(tok[0]);
glyph->rectY = atoi(tok[1]);
glyph->rectWidth = atoi(tok[2]);
glyph->rectHeight = atoi(tok[3]);
errno = 0;
{
long val = strtol(tok[0], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->rectX = val;
}
{
long val = strtol(tok[1], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->rectY = val;
}
{
long val = strtol(tok[2], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->rectWidth = val;
}
{
long val = strtol(tok[3], NULL, 0);
if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX))
return -1;
glyph->rectHeight = val;
}
*q = '"';
p = q + 1;
/* parse code */
@ -514,7 +584,6 @@ static int rdtk_font_load_descriptor(rdtkFont* font, const char* filename)
return rdtk_font_parse_descriptor_buffer(font, (BYTE*) buffer, size);
}
rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
{
int status;
@ -589,7 +658,6 @@ cleanup:
return NULL;
}
static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int imageSize,
BYTE* descriptorData, int descriptorSize)
{
@ -643,7 +711,6 @@ static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int
return font;
}
void rdtk_font_free(rdtkFont* font)
{
if (font)
@ -655,7 +722,6 @@ void rdtk_font_free(rdtkFont* font)
free(font);
}
}
int rdtk_font_engine_init(rdtkEngine* engine)
{
if (!engine->font)
@ -676,7 +742,6 @@ int rdtk_font_engine_init(rdtkEngine* engine)
return 1;
}
int rdtk_font_engine_uninit(rdtkEngine* engine)
{
if (engine->font)

View File

@ -735,7 +735,8 @@ static BOOL tf_peer_suppress_output(rdpContext* context, BYTE allow,
{
if (allow > 0)
{
WLog_DBG(TAG, "Client restore output (%"PRIu16", %"PRIu16") (%"PRIu16", %"PRIu16").", area->left, area->top,
WLog_DBG(TAG, "Client restore output (%"PRIu16", %"PRIu16") (%"PRIu16", %"PRIu16").", area->left,
area->top,
area->right, area->bottom);
}
else
@ -889,8 +890,9 @@ int main(int argc, char* argv[])
freerdp_listener* instance;
char* file;
char name[MAX_PATH];
int port = 3389, i;
long port = 3389, i;
BOOL localOnly = FALSE;
errno = 0;
for (i = 1; i < argc; i++)
{
@ -907,7 +909,7 @@ int main(int argc, char* argv[])
port = strtol(arg, NULL, 10);
if ((port < 1) || (port > 0xFFFF))
if ((port < 1) || (port > 0xFFFF) || (errno != 0))
return -1;
}
else if (strcmp(arg, "--local-only"))

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
@ -40,10 +41,9 @@ int IDcount = 0;
BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
WLog_DBG(TAG, "%d\t(%ld, %ld), (%ld, %ld)",
IDcount, lprcMonitor->left, lprcMonitor->top,
lprcMonitor->right, lprcMonitor->bottom);
IDcount, lprcMonitor->left, lprcMonitor->top,
lprcMonitor->right, lprcMonitor->bottom);
IDcount++;
return TRUE;
}
@ -52,13 +52,12 @@ int main(int argc, char* argv[])
BOOL screen_selected = FALSE;
int index;
wfServer* server;
server = wfreerdp_server_new();
set_screen_id(0);
//handle args
index = 1;
errno = 0;
while (index < argc)
{
//first the args that will cause the program to terminate
@ -72,11 +71,11 @@ int main(int argc, char* argv[])
WLog_INFO(TAG, "Detecting screens...");
WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
for (i=0; ; i++)
for (i = 0; ; i++)
{
if (get_screen_info(i, name, &width, &height, &bpp) != 0)
{
if ( (width * height * bpp) == 0 )
if ((width * height * bpp) == 0)
continue;
WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
@ -101,24 +100,36 @@ int main(int argc, char* argv[])
return 0;
}
if (strcmp("--screen", argv[index]) == 0)
{
UINT32 val;
screen_selected = TRUE;
index++;
if (index == argc)
{
WLog_INFO(TAG, "missing screen id parameter");
return 0;
}
set_screen_id(atoi(argv[index]));
val = strtoul(argv[index], NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return -1;
set_screen_id(val);
index++;
}
if (index == argc - 1)
{
server->port = (DWORD) atoi(argv[index]);
UINT32 val = strtoul(argv[index], NULL, 0);
if ((errno != 0) || (val > UINT32_MAX))
return -1;
server->port = val;
break;
}
}
@ -134,11 +145,11 @@ int main(int argc, char* argv[])
WLog_INFO(TAG, "Detecting screens...");
WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
for (i=0; ; i++)
for (i = 0; ; i++)
{
if (get_screen_info(i, name, &width, &height, &bpp) != 0)
{
if ( (width * height * bpp) == 0 )
if ((width * height * bpp) == 0)
continue;
WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
@ -155,11 +166,9 @@ int main(int argc, char* argv[])
WLog_INFO(TAG, "Starting server");
wfreerdp_server_start(server);
WaitForSingleObject(server->thread, INFINITE);
WLog_INFO(TAG, "Stopping server");
wfreerdp_server_stop(server);
wfreerdp_server_free(server);
return 0;
}

View File

@ -22,6 +22,8 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/ssl.h>
#include <winpr/wnd.h>
@ -172,6 +174,7 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
return status;
arg = shadow_args;
errno = 0;
do
{
@ -181,7 +184,12 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
CommandLineSwitchStart(arg)
CommandLineSwitchCase(arg, "port")
{
server->port = (DWORD) atoi(arg->Value);
long val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
return -1;
server->port = (DWORD) val;
}
CommandLineSwitchCase(arg, "ipc-socket")
{
@ -202,7 +210,7 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
{
char* p;
char* tok[4];
int x, y, w, h;
long x = -1, y = -1, w = -1, h = -1;
char* str = _strdup(arg->Value);
if (!str)
@ -239,13 +247,30 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
*p++ = '\0';
tok[3] = p;
x = atoi(tok[0]);
y = atoi(tok[1]);
w = atoi(tok[2]);
h = atoi(tok[3]);
x = strtol(tok[0], NULL, 0);
if (errno != 0)
goto fail;
y = strtol(tok[1], NULL, 0);
if (errno != 0)
goto fail;
w = strtol(tok[2], NULL, 0);
if (errno != 0)
goto fail;
h = strtol(tok[3], NULL, 0);
if (errno != 0)
goto fail;
fail:
free(str);
if ((x < 0) || (y < 0) || (w < 1) || (h < 1))
if ((x < 0) || (y < 0) || (w < 1) || (h < 1) || (errno != 0))
return -1;
server->subRect.left = x;
@ -333,15 +358,15 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{
/* Select monitors */
index = atoi(arg->Value);
long val = strtol(arg->Value, NULL, 0);
if (index < 0)
if ((val < 0) || (errno != 0))
index = 0;
if (index >= numMonitors)
if (val >= numMonitors)
index = 0;
server->selectedMonitor = index;
server->selectedMonitor = val;
}
else
{

View File

@ -32,26 +32,38 @@
#ifndef _WIN32
#ifndef _strtoui64
#define _strtoui64 strtoull
#endif
#ifndef _strtoi64
#define _strtoi64 strtoll
#endif
#ifndef _rotl
static INLINE UINT32 _rotl(UINT32 value, int shift) {
static INLINE UINT32 _rotl(UINT32 value, int shift)
{
return (value << shift) | (value >> (32 - shift));
}
#endif
#ifndef _rotl64
static INLINE UINT64 _rotl64(UINT64 value, int shift) {
static INLINE UINT64 _rotl64(UINT64 value, int shift)
{
return (value << shift) | (value >> (64 - shift));
}
#endif
#ifndef _rotr
static INLINE UINT32 _rotr(UINT32 value, int shift) {
static INLINE UINT32 _rotr(UINT32 value, int shift)
{
return (value >> shift) | (value << (32 - shift));
}
#endif
#ifndef _rotr64
static INLINE UINT64 _rotr64(UINT64 value, int shift) {
static INLINE UINT64 _rotr64(UINT64 value, int shift)
{
return (value >> shift) | (value << (64 - shift));
}
#endif
@ -63,22 +75,24 @@ static INLINE UINT64 _rotr64(UINT64 value, int shift) {
#else
static INLINE UINT32 _byteswap_ulong(UINT32 _val) {
return (((_val) >> 24) | \
(((_val) & 0x00FF0000) >> 8) | \
(((_val) & 0x0000FF00) << 8) | \
((_val) << 24));
static INLINE UINT32 _byteswap_ulong(UINT32 _val)
{
return (((_val) >> 24) | \
(((_val) & 0x00FF0000) >> 8) | \
(((_val) & 0x0000FF00) << 8) | \
((_val) << 24));
}
static INLINE UINT64 _byteswap_uint64(UINT64 _val) {
return (((_val) << 56) | \
(((_val) << 40) & 0xFF000000000000) | \
(((_val) << 24) & 0xFF0000000000) | \
(((_val) << 8) & 0xFF00000000) | \
(((_val) >> 8) & 0xFF000000) | \
(((_val) >> 24) & 0xFF0000) | \
(((_val) >> 40) & 0xFF00) | \
((_val) >> 56));
static INLINE UINT64 _byteswap_uint64(UINT64 _val)
{
return (((_val) << 56) | \
(((_val) << 40) & 0xFF000000000000) | \
(((_val) << 24) & 0xFF0000000000) | \
(((_val) << 8) & 0xFF00000000) | \
(((_val) >> 8) & 0xFF000000) | \
(((_val) >> 24) & 0xFF0000) | \
(((_val) >> 40) & 0xFF00) | \
((_val) >> 56));
}
#endif
@ -89,7 +103,8 @@ static INLINE UINT64 _byteswap_uint64(UINT64 _val) {
#else
static INLINE UINT16 _byteswap_ushort(UINT16 _val) {
static INLINE UINT16 _byteswap_ushort(UINT16 _val)
{
return (((_val) >> 8) | ((_val) << 8));
}
@ -128,8 +143,10 @@ WINPR_API void* _aligned_realloc(void* memblock, size_t size, size_t alignment);
WINPR_API void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);
WINPR_API void* _aligned_offset_malloc(size_t size, size_t alignment, size_t offset);
WINPR_API void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment, size_t offset);
WINPR_API void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t alignment, size_t offset);
WINPR_API void* _aligned_offset_realloc(void* memblock, size_t size, size_t alignment,
size_t offset);
WINPR_API void* _aligned_offset_recalloc(void* memblock, size_t num, size_t size, size_t alignment,
size_t offset);
WINPR_API size_t _aligned_msize(void* memblock, size_t alignment, size_t offset);

View File

@ -21,6 +21,7 @@
#include "config.h"
#endif
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/user.h>
@ -37,7 +38,8 @@
* Null-terminated ANSI text with CR/LF line endings.
*/
static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId, const void* data,
UINT32* pSize)
{
int size;
char* pDstData = NULL;
@ -46,34 +48,34 @@ static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId
{
char* str = NULL;
size = (int) *pSize;
if (*pSize > INT32_MAX)
return NULL;
size = (int) * pSize;
size = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) data,
size / 2, (CHAR**) &str, 0, NULL, NULL);
size / 2, (CHAR**) &str, 0, NULL, NULL);
if (!str)
return NULL;
pDstData = ConvertLineEndingToCRLF((const char*) str, &size);
free(str);
*pSize = size;
return pDstData;
}
else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
(formatId == ClipboardGetFormatId(clipboard, "UTF8_STRING")) ||
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
(formatId == ClipboardGetFormatId(clipboard, "UTF8_STRING")) ||
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
{
size = (int) *pSize;
size = (INT64) * pSize;
pDstData = ConvertLineEndingToCRLF((const char*) data, &size);
if (!pDstData)
return NULL;
*pSize = size;
return pDstData;
}
@ -86,7 +88,8 @@ static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId
* Null-terminated OEM text with CR/LF line endings.
*/
static void* clipboard_synthesize_cf_oemtext(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_oemtext(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
return clipboard_synthesize_cf_text(clipboard, formatId, data, pSize);
}
@ -97,15 +100,16 @@ static void* clipboard_synthesize_cf_oemtext(wClipboard* clipboard, UINT32 forma
* System locale identifier associated with CF_TEXT
*/
static void* clipboard_synthesize_cf_locale(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_locale(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
UINT32* pDstData = NULL;
pDstData = (UINT32*) malloc(sizeof(UINT32));
if (!pDstData)
return NULL;
*pDstData = 0x0409; /* English - United States */
*pDstData = 0x0409; /* English - United States */
return (void*) pDstData;
}
@ -115,7 +119,8 @@ static void* clipboard_synthesize_cf_locale(wClipboard* clipboard, UINT32 format
* Null-terminated UTF-16 text with CR/LF line endings.
*/
static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
int size;
int status;
@ -123,12 +128,15 @@ static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 f
WCHAR* pDstData = NULL;
if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
(formatId == ClipboardGetFormatId(clipboard, "UTF8_STRING")) ||
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
(formatId == ClipboardGetFormatId(clipboard, "UTF8_STRING")) ||
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
{
size = (int) *pSize;
if (!pSize || (*pSize > INT32_MAX))
return NULL;
size = (int) * pSize;
crlfStr = ConvertLineEndingToCRLF((char*) data, &size);
if (!crlfStr)
@ -152,43 +160,39 @@ static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 f
* Null-terminated UTF-8 string with LF line endings.
*/
static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
int size;
INT64 size;
char* pDstData = NULL;
if (formatId == CF_UNICODETEXT)
{
size = (int) *pSize;
size = (INT64) * pSize;
size = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) data,
size / 2, (CHAR**) &pDstData, 0, NULL, NULL);
size / 2, (CHAR**) &pDstData, 0, NULL, NULL);
if (!pDstData)
return NULL;
size = ConvertLineEndingToLF(pDstData, size);
*pSize = size;
return pDstData;
}
else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
(formatId == ClipboardGetFormatId(clipboard, "text/plain")) ||
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
{
size = (int) *pSize;
size = (INT64) * pSize;
pDstData = (char*) malloc(size);
if (!pDstData)
return NULL;
CopyMemory(pDstData, data, size);
size = ConvertLineEndingToLF((char*) pDstData, size);
*pSize = size;
return pDstData;
}
@ -201,17 +205,16 @@ static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 form
* BITMAPINFO structure followed by the bitmap bits.
*/
static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId, const void* data,
UINT32* pSize)
{
UINT32 SrcSize;
UINT32 DstSize;
BYTE* pDstData;
SrcSize = *pSize;
if (formatId == CF_DIBV5)
{
}
else if (formatId == ClipboardGetFormatId(clipboard, "image/bmp"))
{
@ -231,11 +234,9 @@ static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId,
if (!pDstData)
return NULL;
data = (void*) &((BYTE*) data)[sizeof(BITMAPFILEHEADER)];
data = (void*) & ((BYTE*) data)[sizeof(BITMAPFILEHEADER)];
CopyMemory(pDstData, data, DstSize);
*pSize = DstSize;
return pDstData;
}
@ -248,15 +249,14 @@ static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId,
* BITMAPV5HEADER structure followed by the bitmap color space information and the bitmap bits.
*/
static void* clipboard_synthesize_cf_dibv5(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_cf_dibv5(wClipboard* clipboard, UINT32 formatId, const void* data,
UINT32* pSize)
{
if (formatId == CF_DIB)
{
}
else if (formatId == ClipboardGetFormatId(clipboard, "image/bmp"))
{
}
return NULL;
@ -268,12 +268,12 @@ static void* clipboard_synthesize_cf_dibv5(wClipboard* clipboard, UINT32 formatI
* Bitmap file format.
*/
static void* clipboard_synthesize_image_bmp(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_image_bmp(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
UINT32 SrcSize;
UINT32 DstSize;
BYTE* pDstData;
SrcSize = *pSize;
if (formatId == CF_DIB)
@ -302,16 +302,13 @@ static void* clipboard_synthesize_image_bmp(wClipboard* clipboard, UINT32 format
pFileHeader->bfReserved1 = 0;
pFileHeader->bfReserved2 = 0;
pFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
pDst = &pDstData[sizeof(BITMAPFILEHEADER)];
CopyMemory(pDst, data, SrcSize);
*pSize = DstSize;
return pDstData;
}
else if (formatId == CF_DIBV5)
{
}
return NULL;
@ -323,11 +320,12 @@ static void* clipboard_synthesize_image_bmp(wClipboard* clipboard, UINT32 format
* HTML clipboard format: msdn.microsoft.com/en-us/library/windows/desktop/ms649015/
*/
static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
char* pSrcData = NULL;
char* pDstData = NULL;
int SrcSize = (int) *pSize;
INT64 SrcSize = (INT64) * pSize;
if (formatId == ClipboardGetFormatId(clipboard, "text/html"))
{
@ -347,22 +345,24 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
if ((bom[0] == 0xFF) && (bom[1] == 0xFE))
{
wstr = (WCHAR*) &((BYTE*) data)[2];
wstr = (WCHAR*) & ((BYTE*) data)[2];
ConvertFromUnicode(CP_UTF8, 0, wstr,
(SrcSize - 2) / 2, &pSrcData, 0, NULL, NULL);
(SrcSize - 2) / 2, &pSrcData, 0, NULL, NULL);
}
}
if (!pSrcData)
{
pSrcData = (char*) calloc(1, SrcSize + 1);
if (!pSrcData)
return NULL;
CopyMemory(pSrcData, data, SrcSize);
}
pDstData = (char*) calloc(1, SrcSize + 200);
if (!pDstData)
{
free(pSrcData);
@ -370,12 +370,11 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
}
strcpy(pDstData,
"Version:0.9\r\n"
"StartHTML:0000000000\r\n"
"EndHTML:0000000000\r\n"
"StartFragment:0000000000\r\n"
"EndFragment:0000000000\r\n");
"Version:0.9\r\n"
"StartHTML:0000000000\r\n"
"EndHTML:0000000000\r\n"
"StartFragment:0000000000\r\n"
"EndFragment:0000000000\r\n");
body = strstr(pSrcData, "<body");
if (!body)
@ -389,12 +388,10 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
strcat(pDstData, "<HTML><BODY>");
strcat(pDstData, "<!--StartFragment-->");
/* StartFragment */
sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
CopyMemory(&pDstData[69], num, 10);
strcat(pDstData, pSrcData);
/* EndFragment */
sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
CopyMemory(&pDstData[93], num, 10);
@ -406,7 +403,6 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
/* EndHTML */
sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
CopyMemory(&pDstData[43], num, 10);
*pSize = (UINT32) strlen(pDstData) + 1;
free(pSrcData);
}
@ -420,32 +416,37 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
* HTML text format.
*/
static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 formatId, const void* data, UINT32* pSize)
static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 formatId,
const void* data, UINT32* pSize)
{
int beg;
int end;
long beg;
long end;
char* str;
char* begStr;
char* endStr;
int SrcSize;
int DstSize = -1;
INT64 SrcSize;
long DstSize = -1;
BYTE* pDstData = NULL;
if (formatId == ClipboardGetFormatId(clipboard, "HTML Format"))
{
str = (char*) data;
SrcSize = (int) *pSize;
SrcSize = (INT64) * pSize;
begStr = strstr(str, "StartHTML:");
endStr = strstr(str, "EndHTML:");
if (!begStr || !endStr)
return NULL;
beg = atoi(&begStr[10]);
end = atoi(&endStr[8]);
errno = 0;
beg = strtol(&begStr[10], NULL, 0);
if (beg < 0 || end < 0 || (beg > SrcSize) || (end > SrcSize) || (beg >= end))
if (errno != 0)
return NULL;
end = strtol(&endStr[8], NULL, 0);
if (beg < 0 || end < 0 || (beg > SrcSize) || (end > SrcSize) || (beg >= end) || (errno != 0))
return NULL;
DstSize = end - beg;
@ -466,143 +467,108 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
{
UINT32 formatId;
UINT32 altFormatId;
/**
* CF_TEXT
*/
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
altFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId,
clipboard_synthesize_utf8_string);
clipboard_synthesize_utf8_string);
/**
* CF_OEMTEXT
*/
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
altFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId,
clipboard_synthesize_utf8_string);
clipboard_synthesize_utf8_string);
/**
* CF_UNICODETEXT
*/
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
altFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId,
clipboard_synthesize_utf8_string);
clipboard_synthesize_utf8_string);
/**
* UTF8_STRING
*/
formatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
}
/**
* text/plain
*/
formatId = ClipboardRegisterFormat(clipboard, "text/plain");
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
}
/**
* TEXT
*/
formatId = ClipboardRegisterFormat(clipboard, "TEXT");
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
}
/**
* STRING
*/
formatId = ClipboardRegisterFormat(clipboard, "STRING");
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT,
clipboard_synthesize_cf_text);
clipboard_synthesize_cf_text);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
clipboard_synthesize_cf_oemtext);
clipboard_synthesize_cf_oemtext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
clipboard_synthesize_cf_unicodetext);
clipboard_synthesize_cf_unicodetext);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
clipboard_synthesize_cf_locale);
clipboard_synthesize_cf_locale);
}
/**
@ -612,12 +578,10 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, CF_DIB, CF_DIBV5,
clipboard_synthesize_cf_dibv5);
clipboard_synthesize_cf_dibv5);
altFormatId = ClipboardRegisterFormat(clipboard, "image/bmp");
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
clipboard_synthesize_image_bmp);
clipboard_synthesize_image_bmp);
}
/**
@ -627,55 +591,47 @@ BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
if (formatId && 0)
{
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, CF_DIB,
clipboard_synthesize_cf_dib);
clipboard_synthesize_cf_dib);
altFormatId = ClipboardRegisterFormat(clipboard, "image/bmp");
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
clipboard_synthesize_image_bmp);
clipboard_synthesize_image_bmp);
}
/**
* image/bmp
*/
formatId = ClipboardRegisterFormat(clipboard, "image/bmp");
if (formatId)
{
ClipboardRegisterSynthesizer(clipboard, formatId, CF_DIB,
clipboard_synthesize_cf_dib);
clipboard_synthesize_cf_dib);
ClipboardRegisterSynthesizer(clipboard, formatId, CF_DIBV5,
clipboard_synthesize_cf_dibv5);
clipboard_synthesize_cf_dibv5);
}
/**
* HTML Format
*/
formatId = ClipboardRegisterFormat(clipboard, "HTML Format");
if (formatId)
{
altFormatId = ClipboardRegisterFormat(clipboard, "text/html");
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
clipboard_synthesize_text_html);
clipboard_synthesize_text_html);
}
/**
* text/html
*/
formatId = ClipboardRegisterFormat(clipboard, "text/html");
if (formatId)
{
altFormatId = ClipboardRegisterFormat(clipboard, "HTML Format");
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
clipboard_synthesize_html_format);
clipboard_synthesize_html_format);
}
return TRUE;

View File

@ -21,6 +21,7 @@
#include "config.h"
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -89,6 +90,7 @@ static void reg_load_start(Reg* reg)
return;
reg->buffer = (char*) malloc(file_size + 2);
if (!reg->buffer)
return ;
@ -138,16 +140,20 @@ static RegVal* reg_load_value(Reg* reg, RegKey* key)
data = p[3] + 1;
length = p[1] - p[0];
name = (char*) malloc(length + 1);
if (!name)
return NULL;
memcpy(name, p[0], length);
name[length] = '\0';
value = (RegVal*) malloc(sizeof(RegVal));
if (!value)
{
free(name);
return NULL;
}
value->name = name;
value->type = REG_NONE;
value->next = value->prev = NULL;
@ -163,13 +169,25 @@ static RegVal* reg_load_value(Reg* reg, RegKey* key)
if (value->type == REG_DWORD)
{
value->data.dword = strtoul(data, NULL, 16);
unsigned long val;
errno = 0;
val = strtoul(data, NULL, 16);
if ((errno != 0) || (val > UINT32_MAX))
{
free(value);
free(name);
return NULL;
}
value->data.dword = val;
}
else if (value->type == REG_SZ)
{
p[4] = strchr(data, '"');
p[4][0] = '\0';
value->data.string = _strdup(data);
if (!value->data.string)
{
free(value);
@ -233,8 +251,10 @@ static void reg_insert_key(Reg* reg, RegKey* key, RegKey* subkey)
char* save;
int length;
path = _strdup(subkey->name);
if (!path)
return;
name = strtok_s(path, "\\", &save);
while (name != NULL)
@ -244,6 +264,7 @@ static void reg_insert_key(Reg* reg, RegKey* key, RegKey* subkey)
length = strlen(name);
name += length + 1;
subkey->subname = _strdup(name);
/* TODO: free allocated memory in error case */
if (!subkey->subname)
{
@ -267,17 +288,21 @@ static RegKey* reg_load_key(Reg* reg, RegKey* key)
p[0] = reg->line + 1;
p[1] = strrchr(p[0], ']');
subkey = (RegKey*) malloc(sizeof(RegKey));
if (!subkey)
return NULL;
subkey->values = NULL;
subkey->prev = subkey->next = NULL;
length = p[1] - p[0];
subkey->name = (char*) malloc(length + 1);
if (!subkey->name)
{
free(subkey);
return NULL;
}
memcpy(subkey->name, p[0], length);
subkey->name[length] = '\0';
@ -393,39 +418,40 @@ Reg* reg_open(BOOL read_only)
if (!reg)
return NULL;
reg->read_only = read_only;
reg->filename = WINPR_HKLM_HIVE;
reg->read_only = read_only;
reg->filename = WINPR_HKLM_HIVE;
if (reg->read_only)
{
reg->fp = fopen(reg->filename, "r");
}
else
{
reg->fp = fopen(reg->filename, "r+");
if (reg->read_only)
{
reg->fp = fopen(reg->filename, "r");
}
else
{
reg->fp = fopen(reg->filename, "r+");
if (!reg->fp)
reg->fp = fopen(reg->filename, "w+");
}
if (!reg->fp)
reg->fp = fopen(reg->filename, "w+");
}
if (!reg->fp)
{
free(reg);
return NULL;
}
if (!reg->fp)
{
free(reg);
return NULL;
}
reg->root_key = (RegKey*) malloc(sizeof(RegKey));
reg->root_key = (RegKey*) malloc(sizeof(RegKey));
if (!reg->root_key)
{
fclose(reg->fp);
free(reg);
return NULL;
}
reg->root_key->values = NULL;
reg->root_key->subkeys = NULL;
reg->root_key->name = "HKEY_LOCAL_MACHINE";
reg_load(reg);
reg->root_key->values = NULL;
reg->root_key->subkeys = NULL;
reg->root_key->name = "HKEY_LOCAL_MACHINE";
reg_load(reg);
return reg;
}

View File

@ -33,6 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/print.h>
@ -2855,16 +2856,16 @@ WINSCARDAPI LONG WINAPI PCSC_SCardAddReaderName(HANDLE* key, LPSTR readerName)
}
#ifdef __MACOSX__
unsigned int determineMacOSXVersion()
unsigned int determineMacOSXVersion(void)
{
int mib[2];
size_t len = 0;
char* kernelVersion = NULL;
char* tok = NULL;
unsigned int version = 0;
int majorVersion = 0;
int minorVersion = 0;
int patchVersion = 0;
long majorVersion = 0;
long minorVersion = 0;
long patchVersion = 0;
int count = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_OSRELEASE;
@ -2884,21 +2885,34 @@ unsigned int determineMacOSXVersion()
}
tok = strtok(kernelVersion, ".");
errno = 0;
while (tok)
{
switch (count)
{
case 0:
majorVersion = atoi(tok);
majorVersion = strtol(tok, NULL, 0);
if (errno != 0)
goto fail;
break;
case 1:
minorVersion = atoi(tok);
minorVersion = strtol(tok, NULL, 0);
if (errno != 0)
goto fail;
break;
case 2:
patchVersion = atoi(tok);
patchVersion = strtol(tok, NULL, 0);
if (errno != 0)
goto fail;
break;
}
@ -2964,6 +2978,7 @@ unsigned int determineMacOSXVersion()
version |= (minorVersion << 8) | (patchVersion);
}
fail:
free(kernelVersion);
return version;
}

View File

@ -33,7 +33,6 @@
BOOL IniFile_Load_NextLine(wIniFile* ini, char* str)
{
int length = 0;
ini->nextLine = strtok_s(str, "\n", &ini->tokctx);
if (ini->nextLine)
@ -57,11 +56,9 @@ BOOL IniFile_Load_NextLine(wIniFile* ini, char* str)
int IniFile_Load_String(wIniFile* ini, const char* iniString)
{
long int fileSize;
ini->line = NULL;
ini->nextLine = NULL;
ini->buffer = NULL;
fileSize = (long int) strlen(iniString);
if (fileSize < 1)
@ -73,12 +70,9 @@ int IniFile_Load_String(wIniFile* ini, const char* iniString)
return -1;
CopyMemory(ini->buffer, iniString, fileSize);
ini->buffer[fileSize] = '\n';
ini->buffer[fileSize + 1] = '\0';
IniFile_Load_NextLine(ini, ini->buffer);
return 1;
}
@ -106,10 +100,10 @@ int IniFile_Load_File(wIniFile* ini, const char* filename)
goto out_file;
fileSize = _ftelli64(ini->fp);
if (fileSize < 0)
goto out_file;
if (_fseeki64(ini->fp, 0, SEEK_SET) < 0)
goto out_file;
@ -130,14 +124,10 @@ int IniFile_Load_File(wIniFile* ini, const char* filename)
fclose(ini->fp);
ini->fp = NULL;
ini->buffer[fileSize] = '\n';
ini->buffer[fileSize + 1] = '\0';
IniFile_Load_NextLine(ini, ini->buffer);
return 1;
out_buffer:
free(ini->buffer);
ini->buffer = NULL;
@ -174,9 +164,7 @@ char* IniFile_Load_GetNextLine(wIniFile* ini)
ini->line = ini->nextLine;
ini->lineLength = (int) strlen(ini->line);
IniFile_Load_NextLine(ini, NULL);
return ini->line;
}
@ -290,13 +278,12 @@ wIniFileSection* IniFile_AddSection(wIniFile* ini, const char* name)
{
int new_size;
wIniFileSection** new_sect;
new_size = ini->cSections * 2;
new_sect = (wIniFileSection**) realloc(ini->sections, sizeof(wIniFileSection*) * new_size);
if (!new_sect)
return NULL;
ini->cSections = new_size;
ini->sections = new_sect;
}
@ -326,13 +313,14 @@ wIniFileKey* IniFile_GetKey(wIniFile* ini, wIniFileSection* section, const char*
return key;
}
wIniFileKey* IniFile_AddKey(wIniFile* ini, wIniFileSection* section, const char* name, const char* value)
wIniFileKey* IniFile_AddKey(wIniFile* ini, wIniFileSection* section, const char* name,
const char* value)
{
wIniFileKey* key;
if (!section || !name)
return NULL;
key = IniFile_GetKey(ini, section, name);
if (!key)
@ -341,19 +329,18 @@ wIniFileKey* IniFile_AddKey(wIniFile* ini, wIniFileSection* section, const char*
{
int new_size;
wIniFileKey** new_key;
new_size = section->cKeys * 2;
new_key = (wIniFileKey**) realloc(section->keys, sizeof(wIniFileKey*) * new_size);
if (!new_key)
return NULL;
section->cKeys = new_size;
section->keys = new_key;
}
key = IniFile_Key_New(name, value);
if (!key)
return NULL;
@ -378,7 +365,7 @@ int IniFile_Load(wIniFile* ini)
char* name;
char* value;
char* separator;
char *beg, *end;
char* beg, *end;
wIniFileKey* key = NULL;
wIniFileSection* section = NULL;
@ -392,21 +379,18 @@ int IniFile_Load(wIniFile* ini)
if (line[0] == '[')
{
beg = &line[1];
end = strchr(line, ']');
if (!end)
return -1;
*end = '\0';
IniFile_AddSection(ini, beg);
section = ini->sections[ini->nSections - 1];
}
else
{
separator = strchr(line, '=');
end = separator;
while ((&end[-1] > line) && ((end[-1] == ' ') || (end[-1] == '\t')))
@ -414,23 +398,22 @@ int IniFile_Load(wIniFile* ini)
*end = '\0';
name = line;
beg = separator + 1;
while (*beg && ((*beg == ' ') || (*beg == '\t')))
beg++;
if (*beg == '"')
beg++;
end = &line[ini->lineLength];
while ((end > beg) && ((end[-1] == ' ') || (end[-1] == '\t')))
end--;
if (end[-1] == '"')
end[-1] = '\0';
value = beg;
if (!IniFile_AddKey(ini, section, name, value))
@ -439,39 +422,34 @@ int IniFile_Load(wIniFile* ini)
}
key = NULL;
if (section && section->keys)
key = section->keys[section->nKeys - 1];
}
}
IniFile_Load_Finish(ini);
return 1;
}
int IniFile_ReadBuffer(wIniFile* ini, const char* buffer)
{
int status;
ini->readOnly = TRUE;
ini->filename = NULL;
status = IniFile_Load_String(ini, buffer);
if (status < 0)
return status;
status = IniFile_Load(ini);
status = IniFile_Load(ini);
return status;
}
int IniFile_ReadFile(wIniFile* ini, const char* filename)
{
int status;
ini->readOnly = TRUE;
free(ini->filename);
ini->filename = _strdup(filename);
@ -479,12 +457,11 @@ int IniFile_ReadFile(wIniFile* ini, const char* filename)
return -1;
status = IniFile_Load_File(ini, filename);
if (status < 0)
return status;
status = IniFile_Load(ini);
status = IniFile_Load(ini);
return status;
}
@ -496,23 +473,22 @@ char** IniFile_GetSectionNames(wIniFile* ini, int* count)
int nameLength;
char** sectionNames;
wIniFileSection* section = NULL;
length = (sizeof(char*) * ini->nSections) + sizeof(char);
for (index = 0; index < ini->nSections; index++)
{
section = ini->sections[index];
nameLength = (int) strlen(section->name);
length += (nameLength + 1);
}
sectionNames = (char**) malloc(length);
if (!sectionNames)
return NULL;
p = (char*) &((BYTE*) sectionNames)[sizeof(char*) * ini->nSections];
p = (char*) & ((BYTE*) sectionNames)[sizeof(char*) * ini->nSections];
for (index = 0; index < ini->nSections; index++)
{
sectionNames[index] = p;
@ -523,9 +499,7 @@ char** IniFile_GetSectionNames(wIniFile* ini, int* count)
}
*p = '\0';
*count = ini->nSections;
return sectionNames;
}
@ -538,27 +512,27 @@ char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count
char** keyNames;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return NULL;
length = (sizeof(char*) * pSection->nKeys) + sizeof(char);
for (index = 0; index < pSection->nKeys; index++)
{
pKey = pSection->keys[index];
nameLength = (int) strlen(pKey->name);
length += (nameLength + 1);
}
keyNames = (char**) malloc(length);
if (!keyNames)
return NULL;
p = (char*) &((BYTE*) keyNames)[sizeof(char*) * pSection->nKeys];
p = (char*) & ((BYTE*) keyNames)[sizeof(char*) * pSection->nKeys];
for (index = 0; index < pSection->nKeys; index++)
{
keyNames[index] = p;
@ -569,9 +543,7 @@ char** IniFile_GetSectionKeyNames(wIniFile* ini, const char* section, int* count
}
*p = '\0';
*count = pSection->nKeys;
return keyNames;
}
@ -580,48 +552,44 @@ const char* IniFile_GetKeyValueString(wIniFile* ini, const char* section, const
const char* value = NULL;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return NULL;
pKey = IniFile_GetKey(ini, pSection, key);
if (!pKey)
return NULL;
value = (const char*) pKey->value;
return value;
}
int IniFile_GetKeyValueInt(wIniFile* ini, const char* section, const char* key)
{
int value = 0;
long value = 0;
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
return 0;
pKey = IniFile_GetKey(ini, pSection, key);
if (!pKey)
return 0;
value = atoi(pKey->value);
value = strtol(pKey->value, NULL, 0);
return value;
}
int IniFile_SetKeyValueString(wIniFile* ini, const char* section, const char* key, const char* value)
int IniFile_SetKeyValueString(wIniFile* ini, const char* section, const char* key,
const char* value)
{
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
pSection = IniFile_GetSection(ini, section);
if (!pSection)
@ -643,9 +611,7 @@ int IniFile_SetKeyValueInt(wIniFile* ini, const char* section, const char* key,
char strVal[128];
wIniFileKey* pKey = NULL;
wIniFileSection* pSection = NULL;
sprintf_s(strVal, sizeof(strVal), "%d", value);
pSection = IniFile_GetSection(ini, section);
if (!pSection)
@ -665,30 +631,28 @@ int IniFile_SetKeyValueInt(wIniFile* ini, const char* section, const char* key,
char* IniFile_WriteBuffer(wIniFile* ini)
{
int i, j;
int offset;
int size;
size_t offset;
size_t size;
char* buffer;
wIniFileKey* key;
wIniFileSection* section;
size = 0;
for (i = 0; i < ini->nSections; i++)
{
section = ini->sections[i];
size += (int) (strlen(section->name) + 3);
size += (strlen(section->name) + 3);
for (j = 0; j < section->nKeys; j++)
{
key = section->keys[j];
size += (int) (strlen(key->name) + strlen(key->value) + 2);
size += (strlen(key->name) + strlen(key->value) + 2);
}
size += 1;
}
size += 1;
buffer = malloc(size + 1);
if (!buffer)
@ -700,13 +664,13 @@ char* IniFile_WriteBuffer(wIniFile* ini)
{
section = ini->sections[i];
sprintf_s(&buffer[offset], size - offset, "[%s]\n", section->name);
offset += (int) (strlen(section->name) + 3);
offset += (strlen(section->name) + 3);
for (j = 0; j < section->nKeys; j++)
{
key = section->keys[j];
sprintf_s(&buffer[offset], size - offset, "%s=%s\n", key->name, key->value);
offset += (int) (strlen(key->name) + strlen(key->value) + 2);
offset += (strlen(key->name) + strlen(key->value) + 2);
}
sprintf_s(&buffer[offset], size - offset, "\n");
@ -714,7 +678,6 @@ char* IniFile_WriteBuffer(wIniFile* ini)
}
buffer[offset] = '\0';
return buffer;
}
@ -723,14 +686,12 @@ int IniFile_WriteFile(wIniFile* ini, const char* filename)
int length;
char* buffer;
int ret = 1;
buffer = IniFile_WriteBuffer(ini);
if (!buffer)
return -1;
length = (int) strlen(buffer);
ini->readOnly = FALSE;
if (!filename)
@ -746,9 +707,7 @@ int IniFile_WriteFile(wIniFile* ini, const char* filename)
ret = -1;
fclose(ini->fp);
free(buffer);
return ret;
}
@ -787,6 +746,5 @@ void IniFile_Free(wIniFile* ini)
}
free(ini->sections);
free(ini);
}

View File

@ -1,9 +1,10 @@
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/cmdline.h>
const char* testArgv[] =
static const char* testArgv[] =
{
"mstsc.exe",
"+z",
@ -17,7 +18,7 @@ const char* testArgv[] =
"/v:localhost:3389"
};
COMMAND_LINE_ARGUMENT_A args[] =
static COMMAND_LINE_ARGUMENT_A args[] =
{
{ "v", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "destination server" },
{ "port", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "server port" },
@ -60,10 +61,9 @@ int TestCmdLine(int argc, char* argv[])
{
int status;
DWORD flags;
int width = 0;
int height = 0;
long width = 0;
long height = 0;
COMMAND_LINE_ARGUMENT_A* arg;
flags = COMMAND_LINE_SIGIL_SLASH | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_SIGIL_PLUS_MINUS;
status = CommandLineParseArgumentsA(testArgc, testArgv, args, flags, NULL, NULL, NULL);
@ -146,6 +146,7 @@ int TestCmdLine(int argc, char* argv[])
}
arg = args;
errno = 0;
do
{
@ -153,33 +154,34 @@ int TestCmdLine(int argc, char* argv[])
continue;
printf("Argument: %s\n", arg->Name);
CommandLineSwitchStart(arg)
CommandLineSwitchCase(arg, "v")
{
}
CommandLineSwitchCase(arg, "w")
{
width = atoi(arg->Value);
width = strtol(arg->Value, NULL, 0);
if (errno != 0)
return -1;
}
CommandLineSwitchCase(arg, "h")
{
height = atoi(arg->Value);
height = strtol(arg->Value, NULL, 0);
if (errno != 0)
return -1;
}
CommandLineSwitchDefault(arg)
{
}
CommandLineSwitchEnd(arg)
}
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
if ((width != 1024) || (height != 768))
{
printf("Unexpected width and height: Actual: (%dx%d), Expected: (1024x768)\n", width, height);
printf("Unexpected width and height: Actual: (%ldx%ld), Expected: (1024x768)\n", width, height);
return -1;
}

View File

@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <winpr/ntlm.h>
@ -46,16 +47,16 @@
void usage_and_exit()
{
printf("winpr-hash: NTLM hashing tool\n");
printf("Usage: winpr-hash -u <username> -p <password> [-d <domain>] [-f <_default_,sam>] [-v <_1_,2>]\n");
exit(1);
printf("winpr-hash: NTLM hashing tool\n");
printf("Usage: winpr-hash -u <username> -p <password> [-d <domain>] [-f <_default_,sam>] [-v <_1_,2>]\n");
exit(1);
}
int main(int argc, char* argv[])
{
int index = 1;
int format = 0;
int version = 1;
unsigned long version = 1;
BYTE NtHash[16];
char* User = NULL;
UINT32 UserLength;
@ -63,6 +64,7 @@ int main(int argc, char* argv[])
UINT32 DomainLength;
char* Password = NULL;
UINT32 PasswordLength;
errno = 0;
while (index < argc)
{
@ -112,11 +114,11 @@ int main(int argc, char* argv[])
usage_and_exit();
}
version = atoi(argv[index]);
version = strtoul(argv[index], NULL, 0);
if ((version != 1) && (version != 2))
if (((version != 1) && (version != 2)) || (errno != 0))
{
printf("unknown version %d \n\n", version);
printf("unknown version %lu \n\n", version);
usage_and_exit();
}
}
@ -172,6 +174,7 @@ int main(int argc, char* argv[])
{
for (index = 0; index < 16; index++)
printf("%02"PRIx8"", NtHash[index]);
printf("\n");
}
else if (format == 1)

View File

@ -17,6 +17,8 @@
* limitations under the License.
*/
#include <errno.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/cmdline.h>
@ -441,6 +443,7 @@ static int makecert_context_parse_arguments(MAKECERT_CONTEXT* context, int argc,
}
arg = args;
errno = 0;
do
{
@ -515,17 +518,31 @@ static int makecert_context_parse_arguments(MAKECERT_CONTEXT* context, int argc,
}
CommandLineSwitchCase(arg, "y")
{
long val;
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->duration_years = atoi(arg->Value);
val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val < 0) || (val > INT32_MAX))
return -1;
context->duration_years = strtol(arg->Value, NULL, 0);
}
CommandLineSwitchCase(arg, "m")
{
long val;
if (!(arg->Flags & COMMAND_LINE_ARGUMENT_PRESENT))
continue;
context->duration_months = atoi(arg->Value);
val = strtol(arg->Value, NULL, 0);
if ((errno != 0) || (val < 1) || (val > 12))
return -1;
context->duration_months = val;
}
CommandLineSwitchDefault(arg)
{
@ -952,7 +969,7 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
#ifdef WITH_OPENSSL
int length;
char* entry;
int key_length;
unsigned long key_length;
long serial = 0;
X509_NAME* name = NULL;
const EVP_MD* md = NULL;
@ -1005,7 +1022,10 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{
key_length = atoi(arg->Value);
key_length = strtoul(arg->Value, NULL, 0);
if (errno != 0)
return -1;
}
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
@ -1019,11 +1039,13 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
return -1;
context->rsa = RSA_new();
if (!context->rsa)
{
BN_clear_free(rsa);
return -1;
}
BN_set_word(rsa, RSA_F4);
rc = RSA_generate_key_ex(context->rsa, key_length, rsa, NULL);
BN_clear_free(rsa);
@ -1041,7 +1063,12 @@ int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv)
arg = CommandLineFindArgumentA(args, "#");
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
serial = atoi(arg->Value);
{
serial = strtol(arg->Value, NULL, 0);
if (errno != 0)
return -1;
}
else
serial = (long) GetTickCount64();