Use zero-filled states for all async ops in KDC
authorGreg Hudson <ghudson@mit.edu>
Fri, 28 Oct 2011 16:18:45 +0000 (16:18 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 28 Oct 2011 16:18:45 +0000 (16:18 +0000)
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

src/kdc/dispatch.c
src/kdc/do_as_req.c
src/kdc/kdc_preauth.c

index eeb95ff73799047f58a34f63ed07bd2d63787772..1398a33b67d6f519f0239369716da284264d43ba 100644 (file)
@@ -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;
index e09baf9edb20272974dfb81ed32757c835f70ac0..0d5cbe51587f9b0aa92e81c66bc035d83bfa4fdc 100644 (file)
@@ -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",
index fc7e43bcad7ce9a80558060ae42a9ef89584c599..c106027c6b397476c3f20f209b1db66775a397e0 100644 (file)
@@ -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;