bugfix: update_identity
authorvb
Wed, 20 Aug 2014 20:20:07 +0200
changeset 22e235409d570a
parent 21 89f925c7d5be
child 23 dba569e54163
bugfix: update_identity
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Wed Aug 20 16:11:46 2014 +0200
     1.2 +++ b/src/keymanagement.c	Wed Aug 20 20:20:07 2014 +0200
     1.3 @@ -44,6 +44,22 @@
     1.4          if (status == PEP_OUT_OF_MEMORY)
     1.5              return PEP_OUT_OF_MEMORY;
     1.6  
     1.7 +        if (EMPTY(identity->user_id)) {
     1.8 +            free(identity->user_id);
     1.9 +            identity->user_id = strdup(stored_identity->user_id);
    1.10 +            if (identity->user_id == NULL)
    1.11 +                return PEP_OUT_OF_MEMORY;
    1.12 +            identity->user_id_size = stored_identity->user_id_size;
    1.13 +        }
    1.14 +
    1.15 +        if (EMPTY(identity->username)) {
    1.16 +            free(identity->username);
    1.17 +            identity->username = strdup(stored_identity->username);
    1.18 +            if (identity->username == NULL)
    1.19 +                return PEP_OUT_OF_MEMORY;
    1.20 +            identity->username_size = stored_identity->username_size;
    1.21 +        }
    1.22 +
    1.23          if (EMPTY(identity->fpr)) {
    1.24              identity->fpr = strdup(stored_identity->fpr);
    1.25              assert(identity->fpr);
    1.26 @@ -150,13 +166,14 @@
    1.27      status = PEP_STATUS_OK;
    1.28  
    1.29      if (identity->comm_type != PEP_ct_unknown && !EMPTY(identity->user_id)) {
    1.30 -        if (EMPTY(identity->username)) {
    1.31 +        assert(!EMPTY(identity->username)); // this should not happen
    1.32 +
    1.33 +        if (EMPTY(identity->username)) { // mitigate
    1.34              free(identity->username);
    1.35 -            identity->username = strdup(stored_identity->username);
    1.36 -            assert(identity->username);
    1.37 +            identity->username = strdup("anonymous");
    1.38              if (identity->username == NULL)
    1.39                  return PEP_OUT_OF_MEMORY;
    1.40 -            identity->username_size = stored_identity->username_size;
    1.41 +            identity->username_size = 9;
    1.42          }
    1.43  
    1.44          status = set_identity(session, identity);