pidgin: 85ba6728: Fix up Zephyr g_strlcpy patch

elb at pidgin.im elb at pidgin.im
Thu Aug 11 10:51:46 EDT 2011


----------------------------------------------------------------------
Revision: 85ba672811d9257624fddaf458d25014e3e48f0d
Parent:   779433e1b17424fac62edf24400ed2074bc4a468
Author:   elb at pidgin.im
Date:     07/17/11 13:17:19
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/85ba672811d9257624fddaf458d25014e3e48f0d

Changelog: 

Fix up Zephyr g_strlcpy patch

Changes against parent 779433e1b17424fac62edf24400ed2074bc4a468

  patched  libpurple/protocols/zephyr/ZAsyncLocate.c
  patched  libpurple/protocols/zephyr/ZInit.c
  patched  libpurple/protocols/zephyr/ZRetSubs.c

-------------- next part --------------
============================================================
--- libpurple/protocols/zephyr/ZAsyncLocate.c	0b72496d3138a4fd94f3a3325a31f08599eb86c4
+++ libpurple/protocols/zephyr/ZAsyncLocate.c	0381161c17e3e5520f2188c08ab8a652bbf145bd
@@ -18,6 +18,7 @@ Code_t ZRequestLocations(user, zald, kin
 {
     int retval;
     ZNotice_t notice;
+    size_t userlen, versionlen;
 
     if (ZGetFD() < 0)
 	if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE)
@@ -37,16 +38,18 @@ Code_t ZRequestLocations(user, zald, kin
     if ((retval = ZSendNotice(&notice, auth)) != ZERR_NONE)
 	return(retval);
 
-    if ((zald->user = (char *) malloc(strlen(user)+1)) == NULL) {
+    userlen = strlen(user) + 1;
+    versionlen = strlen(notice.z_version) + 1;
+    if ((zald->user = (char *) malloc(userlen)) == NULL) {
 	return(ENOMEM);
     }
-    if ((zald->version = (char *) malloc(strlen(notice.z_version)+1)) == NULL) {
+    if ((zald->version = (char *) malloc(versionlen)) == NULL) {
 	free(zald->user);
 	return(ENOMEM);
     }
     zald->uid = notice.z_multiuid;
-    g_strlcpy(zald->user,user,strlen(user)+1);
-    g_strlcpy(zald->version,notice.z_version,strlen(notice.z_version)+1);
+    g_strlcpy(zald->user,user,userlen);
+    g_strlcpy(zald->version,notice.z_version,versionlen);
 
     return(ZERR_NONE);
 }
@@ -130,14 +133,17 @@ Code_t ZParseLocations(notice,zald,nlocs
     __locate_next = 0;
     *nlocs = __locate_num;
     if (user) {
+	size_t len;    
 	if (zald) {
-	    if ((*user = (char *) malloc(strlen(zald->user)+1)) == NULL)
+	    len = strlen(zald->user) + 1;
+	    if ((*user = (char *) malloc(len)) == NULL)
 		return(ENOMEM);
-	    g_strlcpy(*user,zald->user,strlen(zald->user)+1);
+	    g_strlcpy(*user,zald->user,len);
 	} else {
-	    if ((*user = (char *) malloc(strlen(notice->z_class_inst)+1)) == NULL)
+	    len = strlen(notice->z_class_inst) + 1;
+	    if ((*user = (char *) malloc(len)) == NULL)
 		return(ENOMEM);
-	    g_strlcpy(*user,notice->z_class_inst,strlen(notice->z_class_inst)+1);
+	    g_strlcpy(*user,notice->z_class_inst,len);
 	}
     }
     return (ZERR_NONE);
============================================================
--- libpurple/protocols/zephyr/ZInit.c	c88ece4673abbbf62adfb1074331f1a1838884d7
+++ libpurple/protocols/zephyr/ZInit.c	bd36bd07d9433eb46c8832b4ecd023866c26deed
@@ -101,7 +101,7 @@ Code_t ZInitialize()
 
 #ifdef ZEPHYR_USES_KERBEROS
     if (krealm) {
-      g_strlcpy(__Zephyr_realm, krealm, REALM_SZ-1);
+      g_strlcpy(__Zephyr_realm, krealm, REALM_SZ);
     } else if ((krb_get_tf_fullname(TKT_FILE, d1, d2, __Zephyr_realm)
 		!= KSUCCESS) &&
 	       ((krbval = krb_get_lrealm(__Zephyr_realm, 1)) != KSUCCESS)) {
============================================================
--- libpurple/protocols/zephyr/ZRetSubs.c	83bbe26d2b017a03af93c865e0b2f1e790392e52
+++ libpurple/protocols/zephyr/ZRetSubs.c	b6c6c255d2f68f39352d607b5f0f771b913016f6
@@ -141,32 +141,37 @@ static Code_t Z_RetSubs(notice, nsubs, a
 		}
 
 		for (ptr=retnotice.z_message,i = 0; i< __subscriptions_num; i++) {
+			size_t len;
+
+			len = strlen(ptr) + 1;
 			__subscriptions_list[i].zsub_class = (char *)
-				malloc((unsigned)strlen(ptr)+1);
+				malloc(len);
 			if (!__subscriptions_list[i].zsub_class) {
 				ZFreeNotice(&retnotice);
 				return (ENOMEM);
 			}
-			g_strlcpy(__subscriptions_list[i].zsub_class,ptr,(unsigned)strlen(ptr));
-			ptr += strlen(ptr)+1;
+			g_strlcpy(__subscriptions_list[i].zsub_class,ptr,len);
+			ptr += len;
+			len = strlen(ptr) + 1;
 			__subscriptions_list[i].zsub_classinst = (char *)
-				malloc((unsigned)strlen(ptr)+1);
+				malloc(len);
 			if (!__subscriptions_list[i].zsub_classinst) {
 				ZFreeNotice(&retnotice);
 				return (ENOMEM);
 			}
-			g_strlcpy(__subscriptions_list[i].zsub_classinst,ptr,(unsigned)strlen(ptr));
-			ptr += strlen(ptr)+1;
+			g_strlcpy(__subscriptions_list[i].zsub_classinst,ptr,len);
+			ptr += len;
 			ptr2 = ptr;
 			if (!*ptr2)
 				ptr2 = "*";
+			len = strlen(ptr2) + 1;
 			__subscriptions_list[i].zsub_recipient = (char *)
-				malloc((unsigned)strlen(ptr2)+1);
+				malloc(len);
 			if (!__subscriptions_list[i].zsub_recipient) {
 				ZFreeNotice(&retnotice);
 				return (ENOMEM);
 			}
-			g_strlcpy(__subscriptions_list[i].zsub_recipient,ptr2,(unsigned)strlen(ptr2));
+			g_strlcpy(__subscriptions_list[i].zsub_recipient,ptr2,len);
 			ptr += strlen(ptr)+1;
 		}
 		ZFreeNotice(&retnotice);


More information about the Commits mailing list