Fix a bug in gpass_cli : sprintf needs final 0 while we must not add it for encryption

This commit is contained in:
Grégory Soutadé 2016-08-20 10:47:54 +02:00
parent 0cc706d260
commit 9b9c36070b

View File

@ -116,7 +116,7 @@ static void encrypt_domain(struct gpass_parameters* params, char* domain,
unsigned char** res, unsigned* out_size)
{
EVP_CIPHER_CTX* evp_ctx;
unsigned size = 2+strlen(domain)+1+strlen(params->username)+1;
unsigned size = 2+strlen(domain)+1+strlen(params->username);
unsigned char* buffer, *tmp;
if (params->verbose)
@ -125,10 +125,10 @@ static void encrypt_domain(struct gpass_parameters* params, char* domain,
if ((size % BLOCK_SIZE))
size = ((size/BLOCK_SIZE)+1)*BLOCK_SIZE;
buffer = malloc(size);
memset(buffer, 0, size);
buffer = malloc(size+1); // Cause snprintf() add a final \0
memset(buffer, 0, size+1);
snprintf((char*)buffer, size, "@@%s;%s", domain, params->username);
snprintf((char*)buffer, size+1, "@@%s;%s", domain, params->username);
tmp = malloc(size);
*res = malloc(size*2);