tests: stop using strndup(), which isn't portable

It's not available on Solaris 10, for example. Since this is just test
code that doesn't need to use an optimized system version, replace it
with the implementation copied from tool_cb_hdr.c.
This commit is contained in:
Dan Fandrich 2023-04-10 10:35:04 -07:00
parent a72a548774
commit 6ed0629901

View File

@ -65,6 +65,17 @@ struct gss_ctx_id_t_desc_struct {
char creds[MAX_CREDS_LENGTH];
};
/* simple implementation of strndup(), which isn't portable */
static char *my_strndup(const char *ptr, size_t len)
{
char *copy = malloc(len + 1);
if(!copy)
return NULL;
memcpy(copy, ptr, len);
copy[len] = '\0';
return copy;
}
OM_uint32 gss_init_sec_context(OM_uint32 *min,
gss_const_cred_id_t initiator_cred_handle,
gss_ctx_id_t *context_handle,
@ -280,7 +291,7 @@ OM_uint32 gss_import_name(OM_uint32 *min,
return GSS_S_FAILURE;
}
name = strndup(input_name_buffer->value, input_name_buffer->length);
name = my_strndup(input_name_buffer->value, input_name_buffer->length);
if(!name) {
*min = GSS_NO_MEMORY;
return GSS_S_FAILURE;