svn rev #21891: trunk/src/lib/krb5/os/

ghudson@MIT.EDU ghudson at MIT.EDU
Thu Feb 5 13:26:49 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=21891
Commit By: ghudson
Log Message:
Coverity was nervous that hst_realm.c's domain_heuristic() wasn't
checking for a NULL return from strchr.  The code was safe because a
previous call to strchr on the same argments was checked, but make
Coverity less nervous by storing the result of that previous call and
reusing it.  Also make the function conform better to our standards.



Changed Files:
U   trunk/src/lib/krb5/os/hst_realm.c
Modified: trunk/src/lib/krb5/os/hst_realm.c
===================================================================
--- trunk/src/lib/krb5/os/hst_realm.c	2009-02-05 18:19:23 UTC (rev 21890)
+++ trunk/src/lib/krb5/os/hst_realm.c	2009-02-05 18:26:47 UTC (rev 21891)
@@ -518,27 +518,28 @@
     krb5_error_code retval = 0, r;
     struct addrlist alist;
     krb5_data drealm;
-    char *cp = NULL;
-    char *fqdn = NULL;
+    char *cp = NULL, *fqdn, *dot;
 
     *realm = NULL;
     if (limit < 0)
 	return 0;
 
     memset(&drealm, 0, sizeof (drealm));
-    if (!(fqdn = strdup(domain))) {
+    fqdn = strdup(domain);
+    if (!fqdn) {
 	retval = ENOMEM;
 	goto cleanup;
     }
 
     /* Upper case the domain (for use as a realm) */
-    for (cp = fqdn; *cp; cp++)
+    for (cp = fqdn; *cp; cp++) {
 	if (islower((int)(*cp)))
 	    *cp = toupper((int)*cp);
+    }
 
     /* Search up to limit parents, as long as we have multiple labels. */
     cp = fqdn;
-    while (limit-- >= 0 && strchr(cp, '.') != NULL) {
+    while (limit-- >= 0 && (dot = strchr(cp, '.')) != NULL) {
 
 	drealm.length = strlen(cp);
 	drealm.data = cp;
@@ -547,19 +548,18 @@
 	r = krb5_locate_kdc(context, &drealm, &alist, 0, SOCK_DGRAM, 0);
 	if (!r) { /* Found a KDC! */
 	    krb5int_free_addrlist(&alist);
-	    if (!(*realm = strdup(cp))) {
+	    *realm = strdup(cp);
+	    if (!*realm) {
 		retval = ENOMEM;
 		goto cleanup;
 	    }
 	    break;
 	}
 
-	cp = strchr(cp, '.');
-	cp++;
+	cp = dot + 1;
     }
 
 cleanup:
-    if (fqdn)
-	free(fqdn);
+    free(fqdn);
     return retval;
 }




More information about the cvs-krb5 mailing list