Ticket #28 : improvement: keymanagement.c: update_identity(): strndup instead of strdup (size is known)
authorEdouard Tisserant
Wed, 09 Mar 2016 10:33:23 +0100
changeset 4988d5b72408060
parent 497 37a111f06c7f
child 499 a6c031512a72
Ticket #28 : improvement: keymanagement.c: update_identity(): strndup instead of strdup (size is known)
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Thu Mar 03 20:27:11 2016 +0100
     1.2 +++ b/src/keymanagement.c	Wed Mar 09 10:33:23 2016 +0100
     1.3 @@ -46,7 +46,8 @@
     1.4  
     1.5          if (EMPTYSTR(identity->user_id)) {
     1.6              free(identity->user_id);
     1.7 -            identity->user_id = strdup(stored_identity->user_id);
     1.8 +            identity->user_id = strndup(stored_identity->user_id, stored_identity->user_id_size);
     1.9 +            assert(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 @@ -54,14 +55,15 @@
    1.14  
    1.15          if (EMPTYSTR(identity->username)) {
    1.16              free(identity->username);
    1.17 -            identity->username = strdup(stored_identity->username);
    1.18 +            identity->username = strndup(stored_identity->username, stored_identity->username_size);
    1.19 +            assert(identity->username);
    1.20              if (identity->username == NULL)
    1.21                  return PEP_OUT_OF_MEMORY;
    1.22              identity->username_size = stored_identity->username_size;
    1.23          }
    1.24  
    1.25          if (EMPTYSTR(identity->fpr)) {
    1.26 -            identity->fpr = strdup(stored_identity->fpr);
    1.27 +            identity->fpr = strndup(stored_identity->fpr, stored_identity->fpr_size);
    1.28              assert(identity->fpr);
    1.29              if (identity->fpr == NULL)
    1.30                  return PEP_OUT_OF_MEMORY;
    1.31 @@ -74,7 +76,7 @@
    1.32              }
    1.33          }
    1.34          else /* !EMPTYSTR(identity->fpr) */ {
    1.35 -            if (strcmp(identity->fpr, stored_identity->fpr) == 0) {
    1.36 +            if (strncmp(identity->fpr, stored_identity->fpr, stored_identity->fpr_size) == 0) {
    1.37                  if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.38                      identity->comm_type = _comm_type_key;
    1.39                  }else{