netpgp : ensure null terminated decryped data
authorEdouard Tisserant
Tue, 12 May 2015 16:37:31 +0200
changeset 272f82971ed62e5
parent 271 18b5097c4428
child 273 1017daf29ff4
netpgp : ensure null terminated decryped data
src/pgp_netpgp.c
     1.1 --- a/src/pgp_netpgp.c	Tue May 12 16:13:44 2015 +0200
     1.2 +++ b/src/pgp_netpgp.c	Tue May 12 16:37:31 2015 +0200
     1.3 @@ -325,11 +325,12 @@
     1.4  
     1.5      _psize = pgp_mem_len(mem);
     1.6      if (_psize){
     1.7 -        if ((_ptext = calloc(1, _psize)) == NULL) {
     1.8 +        if ((_ptext = malloc(_psize + 1)) == NULL) {
     1.9              result = PEP_OUT_OF_MEMORY;
    1.10              goto free_pgp;
    1.11          }
    1.12          memcpy(_ptext, pgp_mem_data(mem), _psize);
    1.13 +        _ptext[_psize] = '\0'; // safeguard for naive users
    1.14          result = PEP_DECRYPTED;
    1.15      }else{
    1.16          result = PEP_DECRYPT_NO_KEY;