From: Greg Hudson Date: Fri, 28 Oct 2011 16:18:45 +0000 (+0000) Subject: Use zero-filled states for all async ops in KDC X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8d54c72ae291cea5c68f810ebe7629520e395105;p=krb5.git Use zero-filled states for all async ops in KDC There have been a couple of uninitialized field bugs in the restructured KDC code, partly because compilers can't find these bugs as easily as they can find uninitialized local variable bugs. Use zero-filled state structures to make this type of bug less likely. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25422 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kdc/dispatch.c b/src/kdc/dispatch.c index eeb95ff73..1398a33b6 100644 --- a/src/kdc/dispatch.c +++ b/src/kdc/dispatch.c @@ -90,9 +90,9 @@ dispatch(void *cb, struct sockaddr *local_saddr, const krb5_fulladdr *from, krb5_data *response = NULL; struct dispatch_state *state; - state = malloc(sizeof(*state)); - if (!state) { - (*respond)(arg, ENOMEM, NULL); + state = k5alloc(sizeof(*state), &retval); + if (state == NULL) { + (*respond)(arg, retval, NULL); return; } state->respond = respond; diff --git a/src/kdc/do_as_req.c b/src/kdc/do_as_req.c index e09baf9ed..0d5cbe515 100644 --- a/src/kdc/do_as_req.c +++ b/src/kdc/do_as_req.c @@ -460,35 +460,16 @@ process_as_req(krb5_kdc_req *request, krb5_data *req_pkt, krb5_enctype useenctype; struct as_req_state *state; - state = malloc(sizeof(*state)); - if (!state) { - (*respond)(arg, ENOMEM, NULL); + state = k5alloc(sizeof(*state), &errcode); + if (state == NULL) { + (*respond)(arg, errcode, NULL); return; } - state->session_key.contents = 0; - state->enc_tkt_reply.authorization_data = NULL; - state->reply.padata = 0; - memset(&state->reply, 0, sizeof(state->reply)); state->respond = respond; state->arg = arg; - state->ticket_reply.enc_part.ciphertext.data = 0; - state->server_keyblock.contents = NULL; - state->client_keyblock.contents = NULL; - state->reply_encpart.enc_padata = 0; - state->client = NULL; - state->server = NULL; state->request = request; - state->e_data = NULL; - state->typed_e_data = FALSE; - state->authtime = 0; - state->c_flags = 0; state->req_pkt = req_pkt; - state->rstate = NULL; - state->sname = 0; - state->cname = 0; - state->pa_context = NULL; state->from = from; - memset(&state->rock, 0, sizeof(state->rock)); #if APPLE_PKINIT asReqDebug("process_as_req top realm %s name %s\n", diff --git a/src/kdc/kdc_preauth.c b/src/kdc/kdc_preauth.c index fc7e43bca..c106027c6 100644 --- a/src/kdc/kdc_preauth.c +++ b/src/kdc/kdc_preauth.c @@ -847,8 +847,8 @@ get_preauth_hint_list(krb5_kdc_req *request, krb5_kdcpreauth_rock rock, *e_data_out = NULL; /* Allocate our state. */ - state = malloc(sizeof(*state)); - if (!state) { + state = calloc(1, sizeof(*state)); + if (state == NULL) { (*respond)(arg); return; } @@ -1168,12 +1168,11 @@ check_padata(krb5_context context, krb5_kdcpreauth_rock rock, return; } - state = malloc(sizeof(*state)); - if (!state) { + state = calloc(1, sizeof(*state)); + if (state == NULL) { (*respond)(arg, ENOMEM); return; } - memset(state, 0, sizeof(*state)); state->respond = respond; state->arg = arg; state->context = context;