From 9b9c36070b125e5115693a944360baf34b3d2269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 20 Aug 2016 10:47:54 +0200 Subject: [PATCH] Fix a bug in gpass_cli : sprintf needs final 0 while we must not add it for encryption --- cli/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/main.c b/cli/main.c index 31848c1..037c7eb 100644 --- a/cli/main.c +++ b/cli/main.c @@ -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);