aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-10-04 17:26:21 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-05 14:38:43 +0200
commit43a40999da17cd163b966ee096e9f76f9646f10a (patch)
treecb38d5601b5e6f8afd084ff174c6c2679f48c70f
parente701913fc8ce621bbe4ba0ed1c3aeadda01820cb (diff)
downloadlibssh-43a40999da17cd163b966ee096e9f76f9646f10a.tar.gz
libssh-43a40999da17cd163b966ee096e9f76f9646f10a.tar.xz
libssh-43a40999da17cd163b966ee096e9f76f9646f10a.zip
agent: Use (PUSH|PULL)_BE_U32 in agent_talk()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
-rw-r--r--src/agent.c26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/agent.c b/src/agent.c
index 96e5a69c..d1ea5c08 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -56,33 +56,13 @@
#include "libssh/session.h"
#include "libssh/poll.h"
#include "libssh/pki.h"
+#include "libssh/bytearray.h"
/* macro to check for "agent failure" message */
#define agent_failed(x) \
(((x) == SSH_AGENT_FAILURE) || ((x) == SSH_COM_AGENT2_FAILURE) || \
((x) == SSH2_AGENT_FAILURE))
-static uint32_t agent_get_u32(const void *vp) {
- const uint8_t *p = (const uint8_t *)vp;
- uint32_t v;
-
- v = (uint32_t)p[0] << 24;
- v |= (uint32_t)p[1] << 16;
- v |= (uint32_t)p[2] << 8;
- v |= (uint32_t)p[3];
-
- return v;
-}
-
-static void agent_put_u32(void *vp, uint32_t v) {
- uint8_t *p = (uint8_t *)vp;
-
- p[0] = (uint8_t)(v >> 24) & 0xff;
- p[1] = (uint8_t)(v >> 16) & 0xff;
- p[2] = (uint8_t)(v >> 8) & 0xff;
- p[3] = (uint8_t)v & 0xff;
-}
-
static size_t atomicio(struct ssh_agent_struct *agent, void *buf, size_t n, int do_read) {
char *b = buf;
size_t pos = 0;
@@ -275,7 +255,7 @@ static int agent_talk(struct ssh_session_struct *session,
len = ssh_buffer_get_len(request);
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
- agent_put_u32(payload, len);
+ PUSH_BE_U32(payload, 0, len);
/* send length and then the request packet */
if (atomicio(session->agent, payload, 4, 0) == 4) {
@@ -299,7 +279,7 @@ static int agent_talk(struct ssh_session_struct *session,
return -1;
}
- len = agent_get_u32(payload);
+ len = PULL_BE_U32(payload, 0);
if (len > 256 * 1024) {
ssh_set_error(session, SSH_FATAL,
"Authentication response too long: %u", len);