From 3b928af75b6e2e2fad82700daaa3943008516eca Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Tue, 23 Feb 1999 03:28:28 +0000 Subject: [PATCH] * kcmd.c (kcmd): Fix up to not call sname_to_principal until after all the addresses in hp have been iterated through to avoid smashing. [krb5-appl/516] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11211 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 6 ++++ src/appl/bsd/kcmd.c | 66 +++++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index 08eb74d77..7c3d772e8 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 22 22:26:32 1999 Tom Yu + + * kcmd.c (kcmd): Fix up to not call sname_to_principal until after + all the addresses in hp have been iterated through to avoid + smashing. [krb5-appl/516] + Wed Feb 17 17:24:11 1999 Tom Yu * klogind.M: Document things a little better, including new diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 6ed5e8d77..3d160e565 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -191,40 +191,7 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, fprintf(stderr, "%s: unknown host\n", *ahost); return (-1); } - - if ((host_save = (char *) malloc(strlen(hp->h_name) + 1)) == NULL) { - fprintf(stderr,"kcmd: no memory\n"); - return(-1); - } - strcpy(host_save, hp->h_name); - - /* If no service is given set to the default service */ - if (!service) service = default_service; - - sin_len = strlen(host_save) + strlen(service) - + (realm ? strlen(realm): 0) + 3; - if ( sin_len < 20 ) sin_len = 20; - - if (!(get_cred = (krb5_creds *)calloc(1, sizeof(krb5_creds)))) { - fprintf(stderr,"kcmd: no memory\n"); - return(-1); - } - status = krb5_sname_to_principal(bsd_context, host_save, service, - KRB5_NT_SRV_HST, &get_cred->server); - if (status) { - fprintf(stderr, "kcmd: krb5_sname_to_principal failed: %s\n", - error_message(status)); - return(-1); - } - - if (realm && *realm) { - free(krb5_princ_realm(bsd_context,get_cred->server)->data); - /*krb5_xfree(krb5_princ_realm(bsd_context,get_cred->server)->data);*/ - - krb5_princ_set_realm_length(bsd_context,get_cred->server,strlen(realm)); - krb5_princ_set_realm_data(bsd_context,get_cred->server,strdup(realm)); - } #ifdef POSIX_SIGNALS sigemptyset(&urgmask); sigaddset(&urgmask, SIGURG); @@ -245,7 +212,6 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, #else sigsetmask(oldmask); #endif /* POSIX_SIGNALS */ - krb5_free_creds(bsd_context, get_cred); return (-1); } sin.sin_family = hp->h_addrtype; @@ -273,15 +239,43 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, continue; } #endif /* !(defined(ultrix) || defined(sun)) */ - perror(host_save); + perror(hp->h_name); #ifdef POSIX_SIGNALS sigprocmask(SIG_SETMASK, &oldmask, (sigset_t*)0); #else sigsetmask(oldmask); #endif /* POSIX_SIGNALS */ - krb5_free_creds(bsd_context, get_cred); return (-1); } + /* If no service is given set to the default service */ + if (!service) service = default_service; + + if (!(get_cred = (krb5_creds *)calloc(1, sizeof(krb5_creds)))) { + fprintf(stderr,"kcmd: no memory\n"); + return(-1); + } + host_save = malloc(strlen(hp->h_name) + 1); + if (host_save == NULL) { + fprintf(stderr, "kcmd: no memory\n"); + free(get_cred); + return -1; + } + strcpy(host_save, hp->h_name); + status = krb5_sname_to_principal(bsd_context, host_save, service, + KRB5_NT_SRV_HST, &get_cred->server); + if (status) { + fprintf(stderr, "kcmd: krb5_sname_to_principal failed: %s\n", + error_message(status)); + return(-1); + } + + if (realm && *realm) { + free(krb5_princ_realm(bsd_context,get_cred->server)->data); + /*krb5_xfree(krb5_princ_realm(bsd_context,get_cred->server)->data);*/ + + krb5_princ_set_realm_length(bsd_context,get_cred->server,strlen(realm)); + krb5_princ_set_realm_data(bsd_context,get_cred->server,strdup(realm)); + } if (fd2p == 0) { write(s, "", 1); lport = 0; -- 2.26.2