Use fixed-size SVC name buffer. Validate length.

This commit is contained in:
Michael Jumper 2014-03-06 11:48:52 -08:00
parent bccc1c7c76
commit cdc532e8ba
3 changed files with 19 additions and 4 deletions

View File

@ -59,7 +59,8 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) {
guac_rdp_svc* svc = (guac_rdp_svc*) entry_points_ex->pExtendedData; guac_rdp_svc* svc = (guac_rdp_svc*) entry_points_ex->pExtendedData;
/* Init channel def */ /* Init channel def */
strcpy(svc_plugin->plugin.channel_def.name, svc->name); strncpy(svc_plugin->plugin.channel_def.name, svc->name,
GUAC_RDP_SVC_MAX_LENGTH);
svc_plugin->plugin.channel_def.options = svc_plugin->plugin.channel_def.options =
CHANNEL_OPTION_INITIALIZED CHANNEL_OPTION_INITIALIZED
| CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_ENCRYPT_RDP

View File

@ -41,16 +41,25 @@ guac_rdp_svc* guac_rdp_alloc_svc(guac_client* client, char* name) {
/* Init SVC */ /* Init SVC */
svc->client = client; svc->client = client;
svc->name = strdup(name);
svc->plugin = NULL; svc->plugin = NULL;
svc->input_pipe = NULL; svc->input_pipe = NULL;
svc->output_pipe = NULL; svc->output_pipe = NULL;
/* Warn about name length */
if (strnlen(name, GUAC_RDP_SVC_MAX_LENGTH+1) > GUAC_RDP_SVC_MAX_LENGTH)
guac_client_log_info(client,
"Static channel name \"%s\" exceeds maximum of %i characters "
"and will be truncated",
name, GUAC_RDP_SVC_MAX_LENGTH);
/* Init name */
strncpy(svc->name, name, GUAC_RDP_SVC_MAX_LENGTH);
svc->name[GUAC_RDP_SVC_MAX_LENGTH] = '\0';
return svc; return svc;
} }
void guac_rdp_free_svc(guac_rdp_svc* svc) { void guac_rdp_free_svc(guac_rdp_svc* svc) {
free(svc->name);
free(svc); free(svc);
} }

View File

@ -35,6 +35,11 @@
#include "compat/winpr-stream.h" #include "compat/winpr-stream.h"
#endif #endif
/**
* The maximum number of characters to allow for each channel name.
*/
#define GUAC_RDP_SVC_MAX_LENGTH 7
/** /**
* Structure describing a static virtual channel, and the corresponding * Structure describing a static virtual channel, and the corresponding
* Guacamole pipes. * Guacamole pipes.
@ -54,7 +59,7 @@ typedef struct guac_rdp_svc {
/** /**
* The name of the RDP channel in use, and the name to use for each pipe. * The name of the RDP channel in use, and the name to use for each pipe.
*/ */
char* name; char name[GUAC_RDP_SVC_MAX_LENGTH+1];
/** /**
* The pipe opened by the Guacamole client, if any. This should be * The pipe opened by the Guacamole client, if any. This should be