check return value of alloc functions, from Charles Longeau

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21745 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-07-31 16:11:25 +00:00
parent d3b77d12db
commit 8d40c2994b
22 changed files with 141 additions and 17 deletions

View File

@@ -188,11 +188,10 @@ make_cred_from_ccred(krb5_context context,
;
if (i) {
cred->authdata.val = malloc(sizeof(cred->authdata.val[0]) * i);
cred->authdata.val = calloc(i, sizeof(cred->authdata.val[0]));
if (cred->authdata.val == NULL)
goto nomem;
cred->authdata.len = i;
memset(cred->authdata.val, 0, sizeof(cred->authdata.val[0]) * i);
for (i = 0; i < cred->authdata.len; i++) {
cred->authdata.val[i].ad_type = incred->authdata[i]->type;
ret = krb5_data_copy(&cred->authdata.val[i].ad_data,
@@ -207,11 +206,10 @@ make_cred_from_ccred(krb5_context context,
;
if (i) {
cred->addresses.val = malloc(sizeof(cred->addresses.val[0]) * i);
cred->addresses.val = calloc(i, sizeof(cred->addresses.val[0]));
if (cred->addresses.val == NULL)
goto nomem;
cred->addresses.len = i;
memset(cred->addresses.val, 0, sizeof(cred->addresses.val[0]) * i);
for (i = 0; i < cred->addresses.len; i++) {
cred->addresses.val[i].addr_type = incred->addresses[i]->type;
@@ -331,6 +329,10 @@ make_ccred_from_cred(krb5_context context,
for (i = 0; i < incred->addresses.len; i++) {
cc_data *addr;
addr = malloc(sizeof(*addr));
if (addr == NULL) {
ret = ENOMEM;
goto fail;
}
addr->type = incred->addresses.val[i].addr_type;
addr->length = incred->addresses.val[i].address.length;
addr->data = malloc(addr->length);

View File

@@ -53,8 +53,12 @@ _krb5_principalname2krb5_principal (krb5_context context,
const Realm realm)
{
krb5_principal p = malloc(sizeof(*p));
if (p == NULL)
return ENOMEM;
copy_PrincipalName(&from, &p->name);
p->realm = strdup(realm);
if (p->realm == NULL)
return ENOMEM;
*principal = p;
return 0;
}

View File

@@ -141,14 +141,16 @@ krb5_auth_con_setaddrs(krb5_context context,
if (auth_context->local_address)
krb5_free_address (context, auth_context->local_address);
else
auth_context->local_address = malloc(sizeof(krb5_address));
if ((auth_context->local_address = malloc(sizeof(krb5_address))) == NULL)
return ENOMEM;
krb5_copy_address(context, local_addr, auth_context->local_address);
}
if (remote_addr) {
if (auth_context->remote_address)
krb5_free_address (context, auth_context->remote_address);
else
auth_context->remote_address = malloc(sizeof(krb5_address));
if ((auth_context->remote_address = malloc(sizeof(krb5_address))) == NULL)
return ENOMEM;
krb5_copy_address(context, remote_addr, auth_context->remote_address);
}
return 0;

View File

@@ -102,7 +102,9 @@ main(int argc, char **argv)
for (t = tests; t->str; ++t) {
int i;
_krb5_n_fold (t->str, strlen(t->str), data, t->n);
ret = _krb5_n_fold (t->str, strlen(t->str), data, t->n);
if (ret)
errx(1, "out of memory");
if (memcmp (data, t->res, t->n) != 0) {
printf ("n-fold(\"%s\", %d) failed\n", t->str, t->n);
printf ("should be: ");

View File

@@ -116,12 +116,23 @@ krb5_storage * KRB5_LIB_FUNCTION
krb5_storage_emem(void)
{
krb5_storage *sp = malloc(sizeof(krb5_storage));
if (sp == NULL)
return NULL;
emem_storage *s = malloc(sizeof(*s));
if (s == NULL) {
free(sp);
return NULL;
}
sp->data = s;
sp->flags = 0;
sp->eof_code = HEIM_ERR_EOF;
s->size = 1024;
s->base = malloc(s->size);
if (s->base == NULL) {
free(sp);
free(s);
return NULL;
}
s->len = 0;
s->ptr = s->base;
sp->fetch = emem_fetch;

View File

@@ -87,6 +87,10 @@ make_path(krb5_context context, struct tr_realm *r,
if(strcmp(p, to) == 0)
break;
tmp = calloc(1, sizeof(*tmp));
if(tmp == NULL){
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
tmp->next = path;
path = tmp;
path->realm = strdup(p);
@@ -107,6 +111,10 @@ make_path(krb5_context context, struct tr_realm *r,
if(strncmp(to, from, p - from) == 0)
break;
tmp = calloc(1, sizeof(*tmp));
if(tmp == NULL){
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
tmp->next = path;
path = tmp;
path->realm = malloc(p - from + 1);
@@ -277,6 +285,10 @@ decode_realms(krb5_context context,
}
if(tr[i] == ','){
tmp = malloc(tr + i - start + 1);
if(tmp == NULL){
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
memcpy(tmp, start, tr + i - start);
tmp[tr + i - start] = '\0';
r = make_realm(tmp);
@@ -290,6 +302,11 @@ decode_realms(krb5_context context,
}
}
tmp = malloc(tr + i - start + 1);
if(tmp == NULL){
free(*realms);
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
memcpy(tmp, start, tr + i - start);
tmp[tr + i - start] = '\0';
r = make_realm(tmp);