diff options
| author | Greg Hudson <ghudson@mit.edu> | 2013-02-09 00:43:35 -0500 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2013-02-09 00:43:35 -0500 |
| commit | 7905cd6a2eddbf264242bb2a85f811878b2da7ab (patch) | |
| tree | 72b4028cbe0e399e1d293e2b718530913f0a2673 /src/lib/gssapi | |
| parent | 92e2bac0f38f7f60a8fc74b5964357212c4289e1 (diff) | |
| download | krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.gz krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.xz krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.zip | |
Add and use k5memdup, k5memdup0 helpers
Add k5-int.h static functions to duplicate byte ranges, optionally
with a trailing zero byte, and set an error code like k5alloc does.
Use them where they would shorten existing code.
Diffstat (limited to 'src/lib/gssapi')
| -rw-r--r-- | src/lib/gssapi/krb5/gssapi_krb5.c | 5 | ||||
| -rw-r--r-- | src/lib/gssapi/krb5/import_cred.c | 6 | ||||
| -rw-r--r-- | src/lib/gssapi/krb5/import_name.c | 6 | ||||
| -rw-r--r-- | src/lib/gssapi/krb5/naming_exts.c | 4 |
4 files changed, 6 insertions, 15 deletions
diff --git a/src/lib/gssapi/krb5/gssapi_krb5.c b/src/lib/gssapi/krb5/gssapi_krb5.c index 31f705d824..04d70a64b6 100644 --- a/src/lib/gssapi/krb5/gssapi_krb5.c +++ b/src/lib/gssapi/krb5/gssapi_krb5.c @@ -800,16 +800,13 @@ krb5_gss_authorize_localname(OM_uint32 *minor, return GSS_S_FAILURE; } - user = k5alloc(local_user->length + 1, &code); + user = k5memdup0(local_user->value, local_user->length, &code); if (user == NULL) { *minor = code; krb5_free_context(context); return GSS_S_FAILURE; } - memcpy(user, local_user->value, local_user->length); - user[local_user->length] = '\0'; - user_ok = krb5_kuserok(context, kname->princ, user); free(user); diff --git a/src/lib/gssapi/krb5/import_cred.c b/src/lib/gssapi/krb5/import_cred.c index 4de6fa65e5..ad9a1110e9 100644 --- a/src/lib/gssapi/krb5/import_cred.c +++ b/src/lib/gssapi/krb5/import_cred.c @@ -614,14 +614,12 @@ krb5_gss_import_cred(OM_uint32 *minor_status, gss_buffer_t token, } /* Decode token. */ - copy = malloc(token->length + 1); + copy = k5memdup0(token->value, token->length, &ret); if (copy == NULL) { status = GSS_S_FAILURE; - *minor_status = ENOMEM; + *minor_status = ret; goto cleanup; } - memcpy(copy, token->value, token->length); - copy[token->length] = '\0'; v = k5_json_decode(copy); if (v == NULL) goto invalid; diff --git a/src/lib/gssapi/krb5/import_name.c b/src/lib/gssapi/krb5/import_name.c index 394aca4fe5..3f5492b99f 100644 --- a/src/lib/gssapi/krb5/import_name.c +++ b/src/lib/gssapi/krb5/import_name.c @@ -196,14 +196,12 @@ krb5_gss_import_name(minor_status, input_name_buffer, stringrep = NULL; - tmp = k5alloc(input_name_buffer->length + 1, &code); + tmp = k5memdup0(input_name_buffer->value, input_name_buffer->length, + &code); if (tmp == NULL) goto cleanup; tmp2 = NULL; - memcpy(tmp, input_name_buffer->value, input_name_buffer->length); - tmp[input_name_buffer->length] = '\0'; - /* Find the appropriate string rep to pass into parse_name. */ if ((input_name_type == GSS_C_NULL_OID) || g_OID_equal(input_name_type, gss_nt_krb5_name) || diff --git a/src/lib/gssapi/krb5/naming_exts.c b/src/lib/gssapi/krb5/naming_exts.c index 535311eb97..f44f0d2cf9 100644 --- a/src/lib/gssapi/krb5/naming_exts.c +++ b/src/lib/gssapi/krb5/naming_exts.c @@ -162,11 +162,9 @@ kg_acceptor_princ(krb5_context context, krb5_gss_name_t name, /* If a host was given, we have to use the canonicalized form of it (as * given by krb5_sname_to_principal) for backward compatibility. */ const krb5_data *d = &name->princ->data[1]; - tmp = k5alloc(d->length + 1, &code); + tmp = k5memdup0(d->data, d->length, &code); if (tmp == NULL) return ENOMEM; - memcpy(tmp, d->data, d->length); - tmp[d->length] = '\0'; host = tmp; } else /* No host was given; use an empty string. */ host = ""; |
