fix #45 : Unchecked return value: update_identity() in message_api.c
authorEdouard Tisserant
Wed, 13 Jul 2016 17:59:36 +0200
changeset 858043a39b5e301
parent 857 349cbf352179
child 860 1f469b5b459a
child 861 03f1f3d3858a
fix #45 : Unchecked return value: update_identity() in message_api.c
src/message_api.c
     1.1 --- a/src/message_api.c	Wed Jul 13 09:08:19 2016 +0200
     1.2 +++ b/src/message_api.c	Wed Jul 13 17:59:36 2016 +0200
     1.3 @@ -1235,22 +1235,26 @@
     1.4  
     1.5  // update comm_type to pEp_ct_pEp if needed
     1.6  
     1.7 -static void _update_identity_for_incoming_message(
     1.8 +static PEP_STATUS _update_identity_for_incoming_message(
     1.9          PEP_SESSION session,
    1.10          const message *src
    1.11      )
    1.12  {
    1.13 -    if (src->from && src->from->user_id && src->from->address) {
    1.14 -        update_identity(session, src->from);
    1.15 -        if (is_a_pEpmessage(src)
    1.16 +    PEP_STATUS status;
    1.17 +    if (src->from && src->from->address) {
    1.18 +        status = update_identity(session, src->from);
    1.19 +        if (status == PEP_STATUS_OK
    1.20 +                && is_a_pEpmessage(src)
    1.21                  && src->from->comm_type >= PEP_ct_OpenPGP_unconfirmed
    1.22                  && src->from->comm_type != PEP_ct_pEp_unconfirmed
    1.23                  && src->from->comm_type != PEP_ct_pEp)
    1.24          {
    1.25              src->from->comm_type |= PEP_ct_pEp_unconfirmed;
    1.26 -            update_identity(session, src->from);
    1.27 +            status = update_identity(session, src->from);
    1.28          }
    1.29 +        return status;
    1.30      }
    1.31 +    return PEP_ILLEGAL_VALUE;
    1.32  }
    1.33  
    1.34  DYNAMIC_API PEP_STATUS _decrypt_message(
    1.35 @@ -1289,7 +1293,10 @@
    1.36  
    1.37      // Update src->from in case we just imported a key
    1.38      // we would need to check signature
    1.39 -    _update_identity_for_incoming_message(session, src);
    1.40 +    status = _update_identity_for_incoming_message(session, src);
    1.41 +    if(status != PEP_STATUS_OK)
    1.42 +        return status;
    1.43 +
    1.44      PEP_cryptotech crypto = determine_encryption_format(src);
    1.45  
    1.46      *dst = NULL;
    1.47 @@ -1494,6 +1501,8 @@
    1.48              // we would need to check signature
    1.49  
    1.50              _update_identity_for_incoming_message(session, src);
    1.51 +            if(status != PEP_STATUS_OK)
    1.52 +                goto pep_error;
    1.53              
    1.54              char *re_ptext = NULL;
    1.55              size_t re_psize;
    1.56 @@ -1637,6 +1646,29 @@
    1.57  
    1.58  }
    1.59  
    1.60 +static void _max_comm_type_from_identity_list(
    1.61 +        identity_list *identities, 
    1.62 +        PEP_SESSION session,
    1.63 +        PEP_comm_type *max_comm_type,
    1.64 +        bool *comm_type_determined
    1.65 +    )
    1.66 +{
    1.67 +    identity_list * il;
    1.68 +    for (il = identities; il != NULL; il = il->next)
    1.69 +    {
    1.70 +        if (il->ident)
    1.71 +        {
    1.72 +            PEP_STATUS status = update_identity(session, il->ident);
    1.73 +            if (status == PEP_STATUS_OK)
    1.74 +            {
    1.75 +                *max_comm_type = _get_comm_type(session, *max_comm_type,
    1.76 +                        il->ident);
    1.77 +                *comm_type_determined = true;
    1.78 +            }
    1.79 +        }
    1.80 +    }
    1.81 +}
    1.82 +
    1.83  DYNAMIC_API PEP_STATUS outgoing_message_color(
    1.84          PEP_SESSION session,
    1.85          message *msg,
    1.86 @@ -1646,7 +1678,6 @@
    1.87      PEP_STATUS status = PEP_STATUS_OK;
    1.88      PEP_comm_type max_comm_type = PEP_ct_pEp;
    1.89      bool comm_type_determined = false;
    1.90 -    identity_list * il;
    1.91  
    1.92      assert(session);
    1.93      assert(msg);
    1.94 @@ -1666,38 +1697,14 @@
    1.95      if (status != PEP_STATUS_OK)
    1.96          return status;
    1.97  
    1.98 -    for (il = msg->to; il != NULL; il = il->next)
    1.99 -    {
   1.100 -        if (il->ident)
   1.101 -        {
   1.102 -            update_identity(session, il->ident);
   1.103 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.104 -                    il->ident);
   1.105 -            comm_type_determined = true;
   1.106 -        }
   1.107 -    }
   1.108 +    _max_comm_type_from_identity_list(msg->to, session,
   1.109 +                                      &max_comm_type, &comm_type_determined);
   1.110  
   1.111 -    for (il = msg->cc; il != NULL; il = il->next)
   1.112 -    {
   1.113 -        if (il->ident)
   1.114 -        {
   1.115 -            update_identity(session, il->ident);
   1.116 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.117 -                    il->ident);
   1.118 -            comm_type_determined = true;
   1.119 -        }
   1.120 -    }
   1.121 +    _max_comm_type_from_identity_list(msg->cc, session,
   1.122 +                                      &max_comm_type, &comm_type_determined);
   1.123          
   1.124 -    for (il = msg->bcc; il != NULL; il = il->next)
   1.125 -    {
   1.126 -        if (il->ident)
   1.127 -        {
   1.128 -            update_identity(session, il->ident);
   1.129 -            max_comm_type = _get_comm_type(session, max_comm_type,
   1.130 -                                           il->ident);
   1.131 -            comm_type_determined = true;
   1.132 -        }
   1.133 -    }
   1.134 +    _max_comm_type_from_identity_list(msg->bcc, session,
   1.135 +                                      &max_comm_type, &comm_type_determined);
   1.136  
   1.137      if (comm_type_determined == false)
   1.138          *color = PEP_rating_undefined;