use user-supplied malloc functions for persistent kssl objects

PR: 1467
Submitted by: Andrei Pelinescu-Onciul <andrei@iptel.org>
This commit is contained in:
Nils Larsch 2007-02-10 10:40:24 +00:00
parent 5eee0253e5
commit 6555dfa486
2 changed files with 33 additions and 14 deletions

View file

@ -784,6 +784,25 @@ kssl_krb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
}
#endif /* OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32 */
/* memory allocation functions for non-temporary storage
* (e.g. stuff that gets saved into the kssl context) */
static void* kssl_calloc(size_t nmemb, size_t size)
{
void* p;
p=OPENSSL_malloc(nmemb*size);
if (p){
memset(p, 0, nmemb*size);
}
return p;
}
#define kssl_malloc(size) OPENSSL_malloc((size))
#define kssl_realloc(ptr, size) OPENSSL_realloc(ptr, size)
#define kssl_free(ptr) OPENSSL_free((ptr))
char
*kstring(char *string)
{
@ -1548,7 +1567,7 @@ kssl_sget_tkt( /* UPDATE */ KSSL_CTX *kssl_ctx,
KSSL_CTX *
kssl_ctx_new(void)
{
return ((KSSL_CTX *) calloc(1, sizeof(KSSL_CTX)));
return ((KSSL_CTX *) kssl_calloc(1, sizeof(KSSL_CTX)));
}
@ -1562,13 +1581,13 @@ kssl_ctx_free(KSSL_CTX *kssl_ctx)
if (kssl_ctx->key) OPENSSL_cleanse(kssl_ctx->key,
kssl_ctx->length);
if (kssl_ctx->key) free(kssl_ctx->key);
if (kssl_ctx->client_princ) free(kssl_ctx->client_princ);
if (kssl_ctx->service_host) free(kssl_ctx->service_host);
if (kssl_ctx->service_name) free(kssl_ctx->service_name);
if (kssl_ctx->keytab_file) free(kssl_ctx->keytab_file);
if (kssl_ctx->key) kssl_free(kssl_ctx->key);
if (kssl_ctx->client_princ) kssl_free(kssl_ctx->client_princ);
if (kssl_ctx->service_host) kssl_free(kssl_ctx->service_host);
if (kssl_ctx->service_name) kssl_free(kssl_ctx->service_name);
if (kssl_ctx->keytab_file) kssl_free(kssl_ctx->keytab_file);
free(kssl_ctx);
kssl_free(kssl_ctx);
return (KSSL_CTX *) NULL;
}
@ -1593,7 +1612,7 @@ kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,
case KSSL_SERVER: princ = &kssl_ctx->service_host; break;
default: return KSSL_CTX_ERR; break;
}
if (*princ) free(*princ);
if (*princ) kssl_free(*princ);
/* Add up all the entity->lengths */
length = 0;
@ -1606,7 +1625,7 @@ kssl_ctx_setprinc(KSSL_CTX *kssl_ctx, int which,
/* Space for the ('@'+realm+NULL | NULL) */
length += ((realm)? realm->length + 2: 1);
if ((*princ = calloc(1, length)) == NULL)
if ((*princ = kssl_calloc(1, length)) == NULL)
return KSSL_CTX_ERR;
else
{
@ -1649,7 +1668,7 @@ kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text)
case KSSL_KEYTAB: string = &kssl_ctx->keytab_file; break;
default: return KSSL_CTX_ERR; break;
}
if (*string) free(*string);
if (*string) kssl_free(*string);
if (!text)
{
@ -1657,7 +1676,7 @@ kssl_ctx_setstring(KSSL_CTX *kssl_ctx, int which, char *text)
return KSSL_CTX_OK;
}
if ((*string = calloc(1, strlen(text) + 1)) == NULL)
if ((*string = kssl_calloc(1, strlen(text) + 1)) == NULL)
return KSSL_CTX_ERR;
else
strcpy(*string, text);
@ -1681,7 +1700,7 @@ kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session)
if (kssl_ctx->key)
{
OPENSSL_cleanse(kssl_ctx->key, kssl_ctx->length);
free(kssl_ctx->key);
kssl_free(kssl_ctx->key);
}
if (session)
@ -1707,7 +1726,7 @@ kssl_ctx_setkey(KSSL_CTX *kssl_ctx, krb5_keyblock *session)
}
if ((kssl_ctx->key =
(krb5_octet FAR *) calloc(1, kssl_ctx->length)) == NULL)
(krb5_octet FAR *) kssl_calloc(1, kssl_ctx->length)) == NULL)
{
kssl_ctx->length = 0;
return KSSL_CTX_ERR;

View file

@ -580,7 +580,7 @@ int SSL_set_session(SSL *s, SSL_SESSION *session)
if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
session->krb5_client_princ_len > 0)
{
s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1);
s->kssl_ctx->client_princ = (char *)OPENSSL_malloc(session->krb5_client_princ_len + 1);
memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ,
session->krb5_client_princ_len);
s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';