]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
* walk_rtree.c (dbgref_dump_principal):Move here from
authorSam Hartman <hartmans@mit.edu>
Thu, 7 Sep 2006 11:12:40 +0000 (11:12 +0000)
committerSam Hartman <hartmans@mit.edu>
Thu, 7 Sep 2006 11:12:40 +0000 (11:12 +0000)
        gc_frm_kdc.c so make check works

* gc_frm_kdc.c (krb5_get_cred_from_kdc_opt): Fill in length of
realm after populating from client

* copy_princ.c (krb5_copy_principal): Always allocate space for realms even if they are empty.  Always defensively null terminate.  Note that realms may still have internal null characters; they are not strings.

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/referrals@18568 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/copy_princ.c
src/lib/krb5/krb/gc_frm_kdc.c
src/lib/krb5/krb/walk_rtree.c

index d16c17b5c6fcd57e8bfeae4e0d38897de700a90d..70dfd91d897e1f9caae9a6ff4748e1c63f6f0eca 100644 (file)
@@ -71,20 +71,19 @@ krb5_copy_principal(krb5_context context, krb5_const_principal inprinc, krb5_pri
             krb5_princ_component(context, tempprinc, i)->data = 0;
     }
 
-    if (tempprinc->realm.length) {
-        tempprinc->realm.data =
-           malloc(tempprinc->realm.length = inprinc->realm.length);
-        if (!tempprinc->realm.data) {
-           for (i = 0; i < nelems; i++)
-                free(krb5_princ_component(context, tempprinc, i)->data);
-           free(tempprinc->data);
-           free(tempprinc);
-           return ENOMEM;
-        }
-       memcpy(tempprinc->realm.data, inprinc->realm.data,
-              inprinc->realm.length);
-    } else
-        tempprinc->realm.data = 0;
+
+        tempprinc->realm.data =
+            malloc((tempprinc->realm.length = inprinc->realm.length) + 1);
+        if (!tempprinc->realm.data) {
+            for (i = 0; i < nelems; i++)
+                free(krb5_princ_component(context, tempprinc, i)->data);
+            free(tempprinc->data);
+            free(tempprinc);
+            return ENOMEM;
+        }
+        memcpy(tempprinc->realm.data, inprinc->realm.data,
+               inprinc->realm.length);
+        tempprinc->realm.data[tempprinc->realm.length] = 0;
 
     *outprinc = tempprinc;
     return 0;
index 2e9b8f223790bedc60791064be48873d66969282..af8689f84dfdd7a5a7505cc243f48ec09d6c65c1 100644 (file)
@@ -796,12 +796,15 @@ krb5_get_cred_from_kdc_opt(krb5_context context, krb5_ccache ccache,
     /* Copy client realm to server if no hint. */
     if (!strcmp(server->realm.data, KRB5_REFERRAL_REALM)) {   // XXX a realm is not a string!
         /* Use the client realm. */
+
 #ifdef DEBUG_REFERRALS
         printf("gc_from_kdc: no server realm supplied, using client realm.\n");
 #endif
-        if (!( server->realm.data = (char *)malloc(client->realm.length)))
-           return ENOMEM;
+                               if (!( server->realm.data = (char *)malloc(client->realm.length+1)))
+                           return ENOMEM;
        memcpy(server->realm.data, client->realm.data, client->realm.length);
+       server->realm.length = client->realm.length;
+       server->realm.data[server->realm.length] = 0;
     }
     /*
      * Retreive initial TGT to match the specified server, either for the
@@ -1043,15 +1046,3 @@ krb5_get_cred_from_kdc_renew(krb5_context context, krb5_ccache ccache,
                                      KDC_OPT_RENEW);
 }
 
-#ifdef DEBUG_REFERRALS
-void dbgref_dump_principal(char *d, krb5_principal p)
-{
-       int n;
-
-       printf("  **%s: ",d);
-       for (n=0;n<p->length;n++)
-         printf("%s<%.*s>",(n>0)?"/":"",p->data[n].length,p->data[n].data);
-       printf("@<%.*s>  (length %d, type %d)\n",p->realm.length,p->realm.data,
-              p->length, p->type);
-}
-#endif
index e6765496120fdc43b3affe9927fdfb77b7b25deb..cb76fb235ea4c37b98a6cecf93c4ff942294356e 100644 (file)
@@ -399,3 +399,16 @@ krb5_walk_realm_tree(krb5_context context, const krb5_data *client, const krb5_d
 #endif
     return 0;
 }
+
+#ifdef DEBUG_REFERRALS
+void dbgref_dump_principal(char *d, krb5_principal p)
+{
+    int n;
+             
+    printf("  **%s: ",d);
+    for (n=0;n<p->length;n++)
+       printf("%s<%.*s>",(n>0)?"/":"",p->data[n].length,p->data[n].data);
+    printf("@<%.*s>  (length %d, type %d)\n",p->realm.length,p->realm.data,
+          p->length, p->type);
+}
+#endif