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);