diff options
author | NIIBE Yutaka <[email protected]> | 2019-07-26 01:00:31 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2019-08-12 01:41:47 +0000 |
commit | ccf5cc8b0b6cee562f7d5598149abcde17440ed4 (patch) | |
tree | 9cc532f429f4fc7267884114394b7ab577d6e9e3 | |
parent | gpg,gpgsm: Handle pkdecrypt responses with/without NUL terminators. (diff) | |
download | gnupg-ccf5cc8b0b6cee562f7d5598149abcde17440ed4.tar.gz gnupg-ccf5cc8b0b6cee562f7d5598149abcde17440ed4.zip |
sm: Fix error checking of decryption result.
* sm/call-agent.c (gpgsm_agent_pkdecrypt): Fix condition.
--
Cherry-pick master commit of:
15fe78184cc66ce6e657a6e949a522d7821f8a1c
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r-- | sm/call-agent.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sm/call-agent.c b/sm/call-agent.c index 2ea309b24..d38dbecaa 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -496,7 +496,8 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, return rc; } - put_membuf (&data, "", 1); /* Make sure it is 0 terminated so we can invoke strtoul safely. */ + /* Make sure it is 0 terminated so we can invoke strtoul safely. */ + put_membuf (&data, "", 1); buf = get_membuf (&data, &len); if (!buf) return gpg_error (GPG_ERR_ENOMEM); @@ -512,14 +513,14 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, if (buf[len-1] != ')') return gpg_error (GPG_ERR_INV_SEXP); len--; /* Drop the final close-paren: */ - p = buf + 8; /* Skip leading parenthesis and the value tag. */ - len -= 8; /* Count only the data of the second part. */ + p = buf + 8; /* Skip leading parenthesis and the value tag. */ + len -= 8; /* Count only the data of the second part. */ } else { /* For compatibility with older gpg-agents handle the old style - incomplete S-exps. */ - len--; /* Do not count the Nul. */ + incomplete S-exps. */ + len--; /* Do not count the Nul. */ p = buf; } @@ -527,8 +528,8 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, if (!n || *endp != ':') return gpg_error (GPG_ERR_INV_SEXP); endp++; - if (endp-p+n > len) - return gpg_error (GPG_ERR_INV_SEXP); /* Oops: Inconsistent S-Exp. */ + if (endp-p+n != len) + return gpg_error (GPG_ERR_INV_SEXP); /* Oops: Inconsistent S-Exp. */ memmove (buf, endp, n); |