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

Re: bug with keytab_any?



"Jacques A. Vidrine" <n@nectar.com> writes:
> I haven't been able to pin it down exactly.  I haven't had a chance to
> wrap my head around keytab_any.  However, I think the following should
> be enough  for someone  who understands  how the  code is  supposed to
> function.

I think the following patch should fix your problem.  It also includes
your do-not-double-free-thru-aliases-on-consecutive-lines fix.

/assar

Index: keytab_any.c
===================================================================
RCS file: /afs/pdc.kth.se/src/packages/kth-krb/SourceRepository/heimdal/lib/krb5/keytab_any.c,v
retrieving revision 1.2
diff -u -w -u -w -r1.2 keytab_any.c
--- keytab_any.c	2001/05/14 06:14:48	1.2
+++ keytab_any.c	2001/06/24 01:41:04
@@ -60,7 +60,8 @@
     krb5_error_code ret;
     char buf[256];
 
-    while (strsep_copy(&name, ",", buf, sizeof(buf)) != -1) {
+    while (strsep_copy(&name, ",", buf, sizeof(buf)) != -1
+	   && buf[0] != '\0') {
 	a = malloc(sizeof(*a));
 	if (a == NULL) {
 	    ret = ENOMEM;
@@ -68,7 +69,7 @@
 	}
 	if (a0 == NULL) {
 	    a0 = a;
-	    a->name = strdup(name);
+	    a->name = strdup(buf);
 	    if (a->name == NULL) {
 		krb5_set_error_string(context, "malloc: out of memory");
 		ret = ENOMEM;
@@ -139,10 +140,8 @@
     ed->a = a;
     ret = krb5_kt_start_seq_get(context, ed->a->kt, &ed->cursor);
     if (ret) {
-	free (ed);
 	free (c->data);
 	c->data = NULL;
-	krb5_set_error_string (context, "malloc: out of memory");
 	return ENOMEM;
     }
     return 0;
@@ -166,14 +165,15 @@
 	    ret2 = krb5_kt_end_seq_get (context, ed->a->kt, &ed->cursor);
 	    if (ret2)
 		return ret2;
-	    ed->a = ed->a->next;
+	    while ((ed->a = ed->a->next) != NULL) {
+		ret2 = krb5_kt_start_seq_get(context, ed->a->kt, &ed->cursor);
+		if (ret2 == 0)
+		    break;
+	    }
 	    if (ed->a == NULL) {
 		krb5_clear_error_string (context);
 		return KRB5_CC_END;
 	    }
-	    ret2 = krb5_kt_start_seq_get(context, ed->a->kt, &ed->cursor);
-	    if (ret2)
-		return ret2;
 	} else
 	    return ret;
     } while (ret == KRB5_CC_END);