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
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;
/* 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
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
#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