From b0240f02abdf2a8e1fe6c24d1dd7b3f6790253dc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Aug 2012 11:50:06 -0700 Subject: [PATCH] Define library prefix/suffix with macros, explicitly define and enforce limit on protocol name length, and overall library name length. --- libguac/include/client.h | 32 ++++++++++++++++++++++++++++++++ libguac/src/client.c | 9 +++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libguac/include/client.h b/libguac/include/client.h index 57852c5d..1ceafe9c 100644 --- a/libguac/include/client.h +++ b/libguac/include/client.h @@ -50,6 +50,38 @@ * @file client.h */ +/** + * String prefix which begins the library filename of all client plugins. + */ +#define GUAC_PROTOCOL_LIBRARY_PREFIX "libguac-client-" + +/** + * String suffix which ends the library filename of all client plugins. + */ +#define GUAC_PROTOCOL_LIBRARY_SUFFIX ".so" + +/** + * The maximum number of characters (COUNTING NULL TERMINATOR) to allow + * for protocol names within the library filename of client plugins. + */ +#define GUAC_PROTOCOL_NAME_LIMIT 256 + +/** + * The maximum number of characters (INCLUDING NULL TERMINATOR) that a + * character array containing the concatenation of the library prefix, + * protocol name, and suffix can contain, assuming the protocol name is + * limited to GUAC_PROTOCOL_NAME_LIMIT characters. + */ +#define GUAC_PROTOCOL_LIBRARY_LIMIT ( \ + \ + sizeof(GUAC_PROTOCOL_LIBRARY_PREFIX) - 1 /* "libguac-client-" */ \ + + GUAC_PROTOCOL_NAME_LIMIT - 1 /* [up to 256 chars] */ \ + + sizeof(GUAC_PROTOCOL_LIBRARY_SUFFIX) - 1 /* ".so" */ \ + + 1 /* NULL terminator */ \ + \ +) + + typedef struct guac_client guac_client; typedef struct guac_client_plugin guac_client_plugin; diff --git a/libguac/src/client.c b/libguac/src/client.c index 759c4f3e..90491b50 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -164,16 +164,17 @@ guac_client_plugin* guac_client_plugin_open(const char* protocol) { const char** client_args; /* Pluggable client */ - char protocol_lib[256] = "libguac-client-"; - + char protocol_lib[GUAC_PROTOCOL_LIBRARY_LIMIT] = + GUAC_PROTOCOL_LIBRARY_PREFIX; + union { guac_client_init_handler* client_init; void* obj; } alias; /* Add protocol and .so suffix to protocol_lib */ - strcat(protocol_lib, protocol); - strcat(protocol_lib, ".so"); + strncat(protocol_lib, protocol, GUAC_PROTOCOL_NAME_LIMIT-1); + strcat(protocol_lib, GUAC_PROTOCOL_LIBRARY_SUFFIX); /* Load client plugin */ client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);