aboutsummaryrefslogtreecommitdiffstats
path: root/agent/genkey.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-10-01 11:21:25 +0000
committerWerner Koch <[email protected]>2015-10-02 08:58:40 +0000
commitddf9dd135acd2b3635bb986f6dfc0e4e446d5fad (patch)
treefc5e83d666ed95c6d2132c2d30bcada72a9ce575 /agent/genkey.c
parentgpg: Fix a practical hang after use of --faked-system-time. (diff)
downloadgnupg-ddf9dd135acd2b3635bb986f6dfc0e4e446d5fad.tar.gz
gnupg-ddf9dd135acd2b3635bb986f6dfc0e4e446d5fad.zip
agent: Fix alignment problem with the second passphrase struct.
* agent/genkey.c (agent_ask_new_passphrase): Use a separate malloc for PI2. Check return value of the malloc function. * agent/command-ssh.c (ssh_identity_register): Use a separate malloc for PI2. Wipe PI2. -- For whatever stupid reasons I once allocated only one memory area and split that into PI and PI2. This is actually a common pattern with malloc but here we used a made up object size and do not take the extra alignment required into account. One of these not yet hit by a (sig)bus PC/VAX hacker bugs. Instead of trying to fix the alignment, it is better to use a second calloc for the second struct. GnuPG-bug-id: 2112 Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'agent/genkey.c')
-rw-r--r--agent/genkey.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/agent/genkey.c b/agent/genkey.c
index 13858cae3..e8195c200 100644
--- a/agent/genkey.c
+++ b/agent/genkey.c
@@ -374,8 +374,16 @@ agent_ask_new_passphrase (ctrl_t ctrl, const char *prompt,
return err;
}
- pi = gcry_calloc_secure (2, sizeof (*pi) + MAX_PASSPHRASE_LEN + 1);
- pi2 = pi + (sizeof *pi + MAX_PASSPHRASE_LEN + 1);
+ pi = gcry_calloc_secure (1, sizeof (*pi) + MAX_PASSPHRASE_LEN + 1);
+ if (!pi)
+ return gpg_error_from_syserror ();
+ pi2 = gcry_calloc_secure (1, sizeof (*pi2) + MAX_PASSPHRASE_LEN + 1);
+ if (!pi2)
+ {
+ err = gpg_error_from_syserror ();
+ xfree (pi2);
+ return err;
+ }
pi->max_length = MAX_PASSPHRASE_LEN + 1;
pi->max_tries = 3;
pi->with_qualitybar = 1;
@@ -422,6 +430,7 @@ agent_ask_new_passphrase (ctrl_t ctrl, const char *prompt,
}
xfree (initial_errtext);
+ xfree (pi2);
xfree (pi);
return err;
}