diff options
author | Werner Koch <[email protected]> | 2008-09-03 09:37:32 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2008-09-03 09:37:32 +0000 |
commit | 5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3 (patch) | |
tree | 187e260d1af072d35a529fd43b765e71bab34108 /agent/command.c | |
parent | 2008-08-30 Moritz <[email protected]> (diff) | |
download | gnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.tar.gz gnupg-5a8bf0bec6e63ebd57d0064be65c08ac331ac9e3.zip |
Fix gpg-preset-passphrase bug.
Cleanups
Diffstat (limited to 'agent/command.c')
-rw-r--r-- | agent/command.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/agent/command.c b/agent/command.c index 92e12e22c..c7853a92c 100644 --- a/agent/command.c +++ b/agent/command.c @@ -271,7 +271,6 @@ parse_keygrip (assuan_context_t ctx, const char *string, unsigned char *buf) { int rc; size_t n; - const unsigned char *p; rc = parse_hexstring (ctx, string, &n); if (rc) @@ -280,8 +279,8 @@ parse_keygrip (assuan_context_t ctx, const char *string, unsigned char *buf) if (n != 20) return set_error (GPG_ERR_ASS_PARAMETER, "invalid length of keygrip"); - for (p=(const unsigned char*)string, n=0; n < 20; p += 2, n++) - buf[n] = xtoi_2 (p); + if (hex2bin (string, buf, 20) < 0) + return set_error (GPG_ERR_BUG, "hex2bin"); return 0; } @@ -1100,7 +1099,7 @@ cmd_preset_passphrase (assuan_context_t ctx, char *line) size_t len; if (!opt.allow_preset_passphrase) - return gpg_error (GPG_ERR_NOT_SUPPORTED); + return set_error (GPG_ERR_NOT_SUPPORTED, "no --allow-preset-passphrase"); rc = parse_keygrip (ctx, line, grip); if (rc) @@ -1135,11 +1134,17 @@ cmd_preset_passphrase (assuan_context_t ctx, char *line) /* If there is a passphrase, use it. Currently, a passphrase is required. */ if (*line) - passphrase = line; + { + /* Do in-place conversion. */ + passphrase = line; + if (!hex2str (passphrase, passphrase, strlen (passphrase)+1, NULL)) + rc = set_error (GPG_ERR_ASS_PARAMETER, "invalid hexstring"); + } else - return gpg_error (GPG_ERR_NOT_IMPLEMENTED); + rc = set_error (GPG_ERR_NOT_IMPLEMENTED, "passphrase is required"); - rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl); + if (!rc) + rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl); if (rc) log_error ("command preset_passwd failed: %s\n", gpg_strerror (rc)); |