From ccfc7fa2f0e0b93e3e5843083ef9fdb6cfad4b33 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Wed, 24 Jan 1996 18:24:27 +0000 Subject: [PATCH] Don't assume that the input_name_buffer is null terminated, when it contains a string. Fix gcc warnings. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7373 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/gssapi/krb5/ChangeLog | 6 ++++++ src/lib/gssapi/krb5/import_name.c | 28 ++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index ded46b1d2..7b17f55fd 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -1,3 +1,9 @@ +Wed Jan 24 13:21:37 1996 Theodore Y. Ts'o + + * import_name.c (krb5_gss_import_name): Don't assume that the + input_name_buffer is null terminated, when it contains a + string. Fix gcc warnings. + Tue Jan 23 13:01:42 1996 Ezra Peisach * configure.in: Check for stdlib.h diff --git a/src/lib/gssapi/krb5/import_name.c b/src/lib/gssapi/krb5/import_name.c index c038392dc..7e00e746b 100644 --- a/src/lib/gssapi/krb5/import_name.c +++ b/src/lib/gssapi/krb5/import_name.c @@ -49,7 +49,7 @@ krb5_gss_import_name(context, minor_status, input_name_buffer, { krb5_principal princ; krb5_error_code code; - char *stringrep; + char *stringrep, *tmp; #ifndef NO_PASSWORD struct passwd *pw; #endif @@ -62,15 +62,16 @@ krb5_gss_import_name(context, minor_status, input_name_buffer, if ((input_name_type != GSS_C_NULL_OID) && g_OID_equal(input_name_type, gss_nt_service_name)) { - char *tmp, *service, *host; + char *service, *host; if ((tmp = - (char *) xmalloc(strlen(input_name_buffer->value)+1)) == NULL) { + (char *) xmalloc(input_name_buffer->length + 1)) == NULL) { *minor_status = ENOMEM; return(GSS_S_FAILURE); } - strcpy(tmp, input_name_buffer->value); + memcpy(tmp, input_name_buffer->value, input_name_buffer->length); + tmp[input_name_buffer->length] = 0; service = tmp; if ((host = strchr(tmp, '@')) == NULL) { @@ -96,25 +97,34 @@ krb5_gss_import_name(context, minor_status, input_name_buffer, input = *((krb5_principal *) input_name_buffer->value); - if (code = krb5_copy_principal(context, input, &princ)) { + if ((code = krb5_copy_principal(context, input, &princ))) { *minor_status = code; return(GSS_S_FAILURE); } } else { stringrep = NULL; + if ((tmp = + (char *) xmalloc(input_name_buffer->length + 1)) == NULL) { + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } + + memcpy(tmp, input_name_buffer->value, input_name_buffer->length); + tmp[input_name_buffer->length] = 0; + if ((input_name_type == GSS_C_NULL_OID) || g_OID_equal(input_name_type, gss_nt_krb5_name) || g_OID_equal(input_name_type, gss_nt_user_name)) { - stringrep = (char *) input_name_buffer->value; + stringrep = (char *) tmp; #ifndef NO_PASSWORD } else if (g_OID_equal(input_name_type, gss_nt_machine_uid_name)) { - if (pw = getpwuid(*((uid_t *) input_name_buffer->value))) + if ((pw = getpwuid(*((uid_t *) input_name_buffer->value)))) stringrep = pw->pw_name; else *minor_status = (OM_uint32) G_NOUSER; } else if (g_OID_equal(input_name_type, gss_nt_string_uid_name)) { - if (pw = getpwuid((uid_t) atoi(input_name_buffer->value))) + if ((pw = getpwuid((uid_t) atoi(tmp)))) stringrep = pw->pw_name; else *minor_status = (OM_uint32) G_NOUSER; @@ -129,6 +139,8 @@ krb5_gss_import_name(context, minor_status, input_name_buffer, code = krb5_parse_name(context, (char *) stringrep, &princ); else return(GSS_S_BAD_NAME); + + xfree(tmp); } /* at this point, a krb5 function has been called to set princ. code -- 2.26.2