Don't assume that the input_name_buffer is null terminated, when it
authorTheodore Tso <tytso@mit.edu>
Wed, 24 Jan 1996 18:24:27 +0000 (18:24 +0000)
committerTheodore Tso <tytso@mit.edu>
Wed, 24 Jan 1996 18:24:27 +0000 (18:24 +0000)
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
src/lib/gssapi/krb5/import_name.c

index ded46b1d2a2dfa4e25b1d872b0b7501f86d68ea9..7b17f55fd6a87bd3362ab37600d63bfab59978a8 100644 (file)
@@ -1,3 +1,9 @@
+Wed Jan 24 13:21:37 1996  Theodore Y. Ts'o  <tytso@dcl>
+
+       * 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  <epeisach@kangaroo.mit.edu>
 
        * configure.in: Check for stdlib.h
index c038392dccc2d6b7eda4857f12d9af4f8dd66ae8..7e00e746be7df4eb21d8641e9b1c4a82ba07f5ab 100644 (file)
@@ -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