adium-1.4 2780:b87a96eb5bfc: * Fix a crash if `kDNSServiceErr_In...

commits at adium.im commits at adium.im
Sun Nov 22 15:56:50 UTC 2009


details:	http://hg.adium.im/adium-1.4/rev/b87a96eb5bfc
revision:	2780:b87a96eb5bfc
author:		Evan Schoenberg
date:		Sun Nov 22 09:58:41 2009 -0600

* Fix a crash if `kDNSServiceErr_Invalid` is returned by `TXTRecordSetValue` which occured because the `%@` was being used for a C string
 * Handle the situation which caused `kDNSServiceErr_Invalid` to be returned by `TXTRecordSetValue` if setting a long status message (≥ 250 characters) by truncating appropriately.

Fixes #11322
(transplanted from 61a5bc1a37d66164492f373e8a8b114ee0d0ba09)

diffs (62 lines):

diff -r e807123cdd27 -r b87a96eb5bfc Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m
--- a/Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m	Sat Nov 21 20:07:58 2009 -0600
+++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvRendezvousData.m	Sun Nov 22 09:58:41 2009 -0600
@@ -32,6 +32,7 @@
  
 #import "AWEzvRendezvousData.h"
 #import "AWEzvSupportRoutines.h"
+#import <AIUtilities/AIStringAdditions.h>
 
 @implementation AWEzvRendezvousData
 
@@ -509,9 +510,48 @@
 			/* TXTRecord */ &txtRecord,
 			/* key */ [key UTF8String],
 			/* size, may be zero */ valueSize,
-			/* value, may be null */ valueToSet /* may be NULL */);
+			/* value, may be null */ valueToSet);
+		
+		if ((txtRecordError == kDNSServiceErr_Invalid) &&
+			[value isKindOfClass:[NSString class]]) {
+			/* kDNSServiceErr_Invalid may be returned if:
+			 *	1. Invalid characters were included (per documentation)
+			 *	2. The length of the value is >= 250 characters (at least for the msg key)
+			 *
+			 * So: First, try stripping out any non-ASCII characters, as I'm not sure what might consitute an
+			 * "illegal character" in a field which requests UTF8.
+			 *
+			 * Then, if that still fails, truncate the string to 248 characters (248,249,250 are the ellipsis).
+			 */
+			valueToSet = [[value dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] bytes];
+			valueSize = strlen(valueToSet);
+
+			txtRecordError = TXTRecordSetValue (
+												/* TXTRecord */ &txtRecord,
+												/* key */ [key UTF8String],
+												/* size, may be zero */ valueSize,
+												/* value, may be null */ valueToSet);
+
+			if (txtRecordError == kDNSServiceErr_Invalid) {
+				valueToSet = [[value stringWithEllipsisByTruncatingToLength:248] UTF8String];
+				valueSize = strlen(valueToSet);
+				txtRecordError = TXTRecordSetValue (
+													/* TXTRecord */ &txtRecord,
+													/* key */ [key UTF8String],
+													/* size, may be zero */ valueSize,
+													/* value, may be null */ valueToSet);				
+			}
+		}
+
 		if (txtRecordError != kDNSServiceErr_NoError) {
-			AWEzvLog(@"Error setting TXTRecord of key=%@ and value=%@", key, valueToSet);
+			if (txtRecordError == kDNSServiceErr_Invalid) {
+				AWEzvLog(@"Error setting TXTRecord of key=%@ and value=%s: Value contains illegal characters", key, valueToSet);
+				
+			} else if (txtRecordError == kDNSServiceErr_NoMemory) {
+				AWEzvLog(@"Error setting TXTRecord of key=%@ and value=%s: Exceeded available storage", key, valueToSet);
+			} else {
+				AWEzvLog(@"Error setting TXTRecord of key=%@ and value=%s: Error is %i", key, valueToSet, txtRecordError);
+			}
 			
 		}
 		


More information about the commits mailing list