merging sync
authorVolker Birk <vb@pep-project.org>
Tue, 28 May 2019 17:08:43 +0200
branchsync
changeset 3755df87c9865aa9
parent 3754 7d9c7bc6f412
parent 3753 7eabcd28a967
child 3756 a4e6110def14
merging
     1.1 --- a/src/pgp_sequoia.c	Tue May 28 17:08:29 2019 +0200
     1.2 +++ b/src/pgp_sequoia.c	Tue May 28 17:08:43 2019 +0200
     1.3 @@ -803,8 +803,11 @@
     1.4                   
     1.5              }
     1.6              else {
     1.7 -                const char* split = strstr(uid_value, "<");
     1.8 -                if (split != uid_value) {       
     1.9 +                // Ok, asan gets really pissed at us using this string directly, SO...
    1.10 +                char* uid_copy = calloc(uid_value_len + 1, 1);
    1.11 +                strlcpy(uid_copy, uid_value, uid_value_len);
    1.12 +                const char* split = strstr(uid_copy, "<");
    1.13 +                if (split != uid_copy) {       
    1.14                      while (split) {
    1.15                          if (isspace(*(split - 1)))
    1.16                              break;
    1.17 @@ -831,9 +834,10 @@
    1.18                      else  
    1.19                          split = NULL;
    1.20                  }
    1.21 -                if (split == NULL) {
    1.22 -                    email = strdup(uid_value);
    1.23 -                }
    1.24 +                if (split == NULL)
    1.25 +                    email = uid_copy;
    1.26 +                else 
    1.27 +                    free(uid_copy);
    1.28              }
    1.29          }
    1.30          
    1.31 @@ -1643,6 +1647,11 @@
    1.32      if (write_status != 0)
    1.33          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Encrypting message");
    1.34  
    1.35 +    pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    1.36 +    ws = NULL;
    1.37 +    if (pgp_status != 0)
    1.38 +        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    1.39 +
    1.40      // Add a terminating NUL for naive users
    1.41      void *t = realloc(*stext, *ssize + 1);
    1.42      if (! t)
    1.43 @@ -1651,13 +1660,6 @@
    1.44      (*stext)[*ssize] = 0;
    1.45  
    1.46   out:
    1.47 -    if (ws) {
    1.48 -        pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    1.49 -        ws = NULL;
    1.50 -        if (pgp_status != 0)
    1.51 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    1.52 -    }
    1.53 -
    1.54      if (signer)
    1.55          pgp_signer_free (signer);
    1.56      if (signing_keypair)
    1.57 @@ -1763,21 +1765,22 @@
    1.58      if (write_status != 0)
    1.59          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Encrypting message");
    1.60  
    1.61 +    pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    1.62 +    ws = NULL;
    1.63 +    if (pgp_status != 0)
    1.64 +        ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    1.65 +
    1.66      // Add a terminating NUL for naive users
    1.67      void *t = realloc(*ctext, *csize + 1);
    1.68 -    if (! t)
    1.69 +    if (! t) {
    1.70 +        free(*ctext);
    1.71 +        *ctext = NULL;
    1.72          ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
    1.73 +    }
    1.74      *ctext = t;
    1.75      (*ctext)[*csize] = 0;
    1.76  
    1.77   out:
    1.78 -    if (ws) {
    1.79 -        pgp_status_t pgp_status = pgp_writer_stack_finalize (&err, ws);
    1.80 -        ws = NULL;
    1.81 -        if (pgp_status != 0)
    1.82 -            ERROR_OUT(err, PEP_UNKNOWN_ERROR, "Flushing writer");
    1.83 -    }
    1.84 -
    1.85      if (signer)
    1.86          pgp_signer_free (signer);
    1.87      if (signing_keypair)
    1.88 @@ -2041,6 +2044,7 @@
    1.89      pgp_error_t err = NULL;
    1.90      pgp_tpk_t tpk = NULL;
    1.91      pgp_writer_t armor_writer = NULL;
    1.92 +    pgp_writer_t memory_writer = NULL;
    1.93  
    1.94      assert(session);
    1.95      assert(fpr);
    1.96 @@ -2057,13 +2061,12 @@
    1.97      status = tpk_find_by_fpr_hex(session, fpr, secret, &tpk, NULL);
    1.98      ERROR_OUT(NULL, status, "Looking up TSK for %s", fpr);
    1.99  
   1.100 -    pgp_writer_t memory_writer = pgp_writer_alloc((void **) key_data, size);
   1.101 +    memory_writer = pgp_writer_alloc((void **) key_data, size);
   1.102      if (! memory_writer)
   1.103          ERROR_OUT(NULL, PEP_UNKNOWN_ERROR, "creating memory writer");
   1.104      armor_writer = pgp_armor_writer_new(&err, memory_writer,
   1.105                                          PGP_ARMOR_KIND_PUBLICKEY, NULL, 0);
   1.106      if (! armor_writer) {
   1.107 -        pgp_writer_free(memory_writer);
   1.108          ERROR_OUT(err, PEP_UNKNOWN_ERROR, "creating armored writer");
   1.109      }
   1.110  
   1.111 @@ -2081,6 +2084,15 @@
   1.112      if (armor_writer)
   1.113          pgp_writer_free(armor_writer);
   1.114  
   1.115 +    if (memory_writer) {
   1.116 +        if (status == PEP_STATUS_OK) {
   1.117 +            // Add a trailing NUL.
   1.118 +            pgp_writer_write(NULL, memory_writer, "", 1);
   1.119 +        }
   1.120 +
   1.121 +        pgp_writer_free(memory_writer);
   1.122 +    }
   1.123 +
   1.124      if (tpk)
   1.125          pgp_tpk_free(tpk);
   1.126  
   1.127 @@ -2655,4 +2667,3 @@
   1.128        fpr, *has_private ? "priv" : "pub", pEp_status_to_string(status));
   1.129      return status;
   1.130  }
   1.131 -