--- a/pkcs11/rpc-layer/gck-rpc-dispatch.c
+++ b/pkcs11/rpc-layer/gck-rpc-dispatch.c
@@ -2178,7 +2178,7 @@
 static int pkcs11_socket = -1;
 
 /* The unix socket path, that we listen on */
-static char pkcs11_socket_path[MAXPATHLEN] = { 0, };
+static char *pkcs11_socket_path = NULL;
 
 /* A linked list of dispatcher threads */
 static DispatchState *pkcs11_dispatchers = NULL;
@@ -2258,9 +2258,11 @@
 	pkcs11_socket = -1;
 
 	/* Delete our unix socket */
-	if(pkcs11_socket_path[0])
+	if(pkcs11_socket_path) {
 		unlink (pkcs11_socket_path);
-	pkcs11_socket_path[0] = 0;
+		free (pkcs11_socket_path);
+		pkcs11_socket_path = NULL;
+	}
 
 	/* Stop all of the dispatch threads */
 	for (ds = pkcs11_dispatchers; ds; ds = next) {
@@ -2295,8 +2297,12 @@
 	assert (pkcs11_socket == -1);
 	assert (pkcs11_dispatchers == NULL);
 
-	snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path), 
-	          "%s/socket.pkcs11", prefix);
+	if (pkcs11_socket_path)
+		free (pkcs11_socket_path);
+
+	if ((pkcs11_socket_path = malloc (strlen (prefix) + strlen ("/socket.pkcs11") + 1)) == NULL)
+		return -1;
+	sprintf (pkcs11_socket_path, "%s/socket.pkcs11", prefix);
 
 	sock = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (sock < 0) {
@@ -2337,9 +2343,11 @@
 	pkcs11_socket = -1;
 
 	/* Delete our unix socket */
-	if(pkcs11_socket_path[0])
+	if(pkcs11_socket_path) {
 		unlink (pkcs11_socket_path);
-	pkcs11_socket_path[0] = 0;
+		free (pkcs11_socket_path);
+		pkcs11_socket_path = NULL;
+	}
 
 	/* Stop all of the dispatch threads */
 	for (ds = pkcs11_dispatchers; ds; ds = next) {
--- a/pkcs11/rpc-layer/gck-rpc-module.c
+++ b/pkcs11/rpc-layer/gck-rpc-module.c
@@ -59,7 +59,7 @@
 static pid_t pkcs11_initialized_pid = 0;
 
 /* The socket to connect to */
-static char pkcs11_socket_path[MAXPATHLEN] = { 0, };
+static char *pkcs11_socket_path = NULL;
 
 /* The error used by us when parsing of rpc message fails */
 #define PARSE_ERROR   CKR_DEVICE_ERROR
@@ -100,10 +100,13 @@
 		*(value++) = 0;
 
 	/* Setup the socket path from the arguments */
-	if (strcmp (arg, "socket") == 0)
-		snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path), "%s", value);
-	else
+	if (strcmp (arg, "socket") == 0) {
+		if (pkcs11_socket_path)
+			free (pkcs11_socket_path);
+		pkcs11_socket_path = strdup (value);
+	} else {
 		warning (("unrecognized argument: %s", arg));
+	}
 }
 
 static void
@@ -225,7 +228,10 @@
 	assert (cs);
 	assert (cs->socket == -1);
 	assert (cs->call_status == CALL_INVALID);
-	
+
+	if (!pkcs11_socket_path)
+		return CKR_FUNCTION_FAILED;
+
 	debug (("connecting to: %s", pkcs11_socket_path));
 		
 	addr.sun_family = AF_UNIX;
@@ -1177,12 +1183,15 @@
 		}
 		
 		/* Lookup the socket path, append '.pkcs11' */
-		if (pkcs11_socket_path[0] == 0) {
-			pkcs11_socket_path[0] = 0;
+		if (pkcs11_socket_path == NULL) {
 			path = getenv ("GNOME_KEYRING_SOCKET");
 			if (path && path[0]) {
-				snprintf (pkcs11_socket_path, sizeof (pkcs11_socket_path), "%s.pkcs11", path);
-				pkcs11_socket_path[sizeof (pkcs11_socket_path) - 1] = 0;
+				if ((pkcs11_socket_path = malloc (strlen (path) + strlen (".pkcs11") + 1)) == NULL) {
+					warning (("can't malloc memory"));
+					ret = CKR_HOST_MEMORY;
+					goto done;
+				}
+				sprintf (pkcs11_socket_path, "%s.pkcs11", path);
 			}
 		}
 
@@ -1206,7 +1215,10 @@
 		} else if (ret != CKR_CRYPTOKI_ALREADY_INITIALIZED) {
 			pkcs11_initialized = 0;
 			pkcs11_initialized_pid = 0;
-			pkcs11_socket_path[0] = 0;
+			if (pkcs11_socket_path) {
+				free (pkcs11_socket_path);
+				pkcs11_socket_path = NULL;
+			}
 		}
 			
 	pthread_mutex_unlock (&init_mutex);
@@ -1242,8 +1254,11 @@
 		/* This should stop all other calls in */
 		pkcs11_initialized = 0;
 		pkcs11_initialized_pid = 0;
-		pkcs11_socket_path[0] = 0;
-		
+		if (pkcs11_socket_path) {
+			free (pkcs11_socket_path);
+			pkcs11_socket_path = NULL;
+		}
+
 	pthread_mutex_unlock (&init_mutex);
 	
 	debug (("C_Finalize: %d", CKR_OK));
