Fixed #32 : assert(keylist) without if in keymanagement.c:238
authorEdouard Tisserant
Wed, 09 Mar 2016 12:52:54 +0100
changeset 499a6c031512a72
parent 498 8d5b72408060
child 500 a0baa88ec3e3
Fixed #32 : assert(keylist) without if in keymanagement.c:238
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Wed Mar 09 10:33:23 2016 +0100
     1.2 +++ b/src/keymanagement.c	Wed Mar 09 12:52:54 2016 +0100
     1.3 @@ -179,6 +179,9 @@
     1.4  
     1.5          status = set_identity(session, identity);
     1.6          assert(status == PEP_STATUS_OK);
     1.7 +        if (status != PEP_STATUS_OK) {
     1.8 +            return status;
     1.9 +        }
    1.10      }
    1.11  
    1.12      if (identity->comm_type != PEP_ct_compromized &&
    1.13 @@ -239,6 +242,9 @@
    1.14          bool expired;
    1.15          status = key_expired(session, keylist->value, &expired);
    1.16          assert(status == PEP_STATUS_OK);
    1.17 +        if (status != PEP_STATUS_OK) {
    1.18 +            goto free_keylist;
    1.19 +        }
    1.20  
    1.21          if (status == PEP_STATUS_OK && expired) {
    1.22              timestamp *ts = new_timestamp(time(NULL) + KEY_EXPIRE_DELTA);
    1.23 @@ -251,15 +257,23 @@
    1.24          free(identity->fpr);
    1.25      identity->fpr = strdup(keylist->value);
    1.26      assert(identity->fpr);
    1.27 -    free_stringlist(keylist);
    1.28 -    if (identity->fpr == NULL)
    1.29 -        return PEP_OUT_OF_MEMORY;
    1.30 +    if (identity->fpr == NULL){
    1.31 +        status = PEP_OUT_OF_MEMORY;
    1.32 +        goto free_keylist;
    1.33 +    }
    1.34      identity->fpr_size = strlen(identity->fpr);
    1.35  
    1.36      status = set_identity(session, identity);
    1.37      assert(status == PEP_STATUS_OK);
    1.38 +    if (status != PEP_STATUS_OK) {
    1.39 +        goto free_keylist;
    1.40 +    }
    1.41  
    1.42      return PEP_STATUS_OK;
    1.43 +
    1.44 +free_keylist:
    1.45 +    free_stringlist(keylist);
    1.46 +    return status;
    1.47  }
    1.48  
    1.49  DYNAMIC_API PEP_STATUS register_examine_function(
    1.50 @@ -285,26 +299,37 @@
    1.51  {
    1.52      PEP_SESSION session;
    1.53      pEp_identity *identity;
    1.54 -    PEP_STATUS status = init(&session);
    1.55 +    PEP_STATUS status;
    1.56  
    1.57 +    assert(retrieve_next_identity);
    1.58 +    assert(management);
    1.59 +
    1.60 +    if (!retrieve_next_identity || !management)
    1.61 +        return PEP_ILLEGAL_VALUE;
    1.62 +
    1.63 +    status = init(&session);
    1.64      assert(status == PEP_STATUS_OK);
    1.65      if (status != PEP_STATUS_OK)
    1.66          return status;
    1.67  
    1.68 -    assert(retrieve_next_identity);
    1.69 -    assert(management);
    1.70 -
    1.71      log_event(session, "keymanagement thread started", "pEp engine", NULL, NULL);
    1.72  
    1.73 -    while ((identity = retrieve_next_identity(management))) {
    1.74 +    while ((identity = retrieve_next_identity(management))) 
    1.75 +    {
    1.76          assert(identity->address);
    1.77 -        DEBUG_LOG("do_keymanagement", "retrieve_next_identity", identity->address);
    1.78 -        if (identity->me) {
    1.79 -            status = myself(session, identity);
    1.80 +        if(identity->address)
    1.81 +        {
    1.82 +            DEBUG_LOG("do_keymanagement", "retrieve_next_identity", identity->address);
    1.83 +
    1.84 +            if (identity->me) {
    1.85 +                status = myself(session, identity);
    1.86 +            } else {
    1.87 +                status = recv_key(session, identity->address);
    1.88 +            }
    1.89 +
    1.90              assert(status != PEP_OUT_OF_MEMORY);
    1.91 -        } else {
    1.92 -            status = recv_key(session, identity->address);
    1.93 -            assert(status != PEP_OUT_OF_MEMORY);
    1.94 +            if(status == PEP_OUT_OF_MEMORY)
    1.95 +                return PEP_OUT_OF_MEMORY;
    1.96          }
    1.97          free_identity(identity);
    1.98      }