[gnome-user-share] Bug 586752 – Limit DNSSDServiceName string length



commit e00c0a2b504f165b118f40ee8a74954849e91020
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jun 25 11:16:47 2009 +0100

    Bug 586752 â?? Limit DNSSDServiceName string length
    
    Service names are limited to 63 bytes, so truncate overly long strings.
    
    Spotted by Tomas Bzatek <tbzatek redhat com>

 src/http.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/http.c b/src/http.c
index 0cf22ff..164b291 100644
--- a/src/http.c
+++ b/src/http.c
@@ -52,6 +52,9 @@
 #include "user_share-private.h"
 #include "http.h"
 
+/* From avahi-common/domain.h */
+#define AVAHI_LABEL_MAX 64
+
 #ifdef HAVE_DBUS_1_1
 static char *dbus_session_id;
 #endif
@@ -99,12 +102,22 @@ get_port (void)
 	return ntohs (addr.sin_port);
 }
 
+static char *
+truncate_name (const char *name)
+{
+	const char *end;
+
+	end = g_utf8_find_prev_char (name, name + 64);
+	g_assert (end != NULL);
+	return g_strndup (name, end - name);
+}
 
 static char *
 get_share_name (void)
 {
 	static char *name = NULL;
 	const char *host_name;
+	char *str;
 
 	if (name == NULL) {
 		host_name = g_get_host_name ();
@@ -128,6 +141,14 @@ get_share_name (void)
 		}
 
 	}
+	/* And truncate */
+	if (strlen (name) < AVAHI_LABEL_MAX)
+		return name;
+
+	str = truncate_name (name);
+	g_free (name);
+	name = str;
+
 	return name;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]