diff --git a/guest-comm/host-guest-comm-2.0/host_instance_mgmt.c b/guest-comm/host-guest-comm-2.0/host_instance_mgmt.c index 5d6f1d78..6fb7d069 100644 --- a/guest-comm/host-guest-comm-2.0/host_instance_mgmt.c +++ b/guest-comm/host-guest-comm-2.0/host_instance_mgmt.c @@ -294,9 +294,17 @@ void vio_full_disconnect(instance_t *instance) * * Returns a pointer to the instance name on success, or NULL on failure. */ -char *file_to_instance_name(char *filename, char* instance_name) { +char *file_to_instance_name(char *filename, char* instance_name, + unsigned int inst_name_len) { int rc; - rc = sscanf(filename, "cgcs.messaging.%[^.].sock", instance_name); + char format_string[100]; + + if (inst_name_len == 0) + return NULL; + + snprintf(format_string, sizeof(format_string), + "cgcs.messaging.%%%d[^.].sock", inst_name_len-1); + rc = sscanf(filename, format_string, instance_name); if (rc == 1) return instance_name; else @@ -328,7 +336,7 @@ static void socket_deleted(char *fn) if (!fn) return; - instance_name = file_to_instance_name(fn, buf); + instance_name = file_to_instance_name(fn, buf, sizeof(buf)); if (!instance_name) // Not a file we care about. return; @@ -429,7 +437,7 @@ static int socket_added(char *filename) return -1; } - instance_name = file_to_instance_name(filename, namebuf); + instance_name = file_to_instance_name(filename, namebuf, sizeof(namebuf)); if (!instance_name) { // Not a bug, just not a file we care about. return -1;