mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
agent: Avoid 1KB temporary buffer in agent_talk
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I9acffc6deef534659f89ca8ddb0cd60b325aaeb2
This commit is contained in:
30
src/agent.c
30
src/agent.c
@@ -251,7 +251,8 @@ static int agent_decode_reply(struct ssh_session_struct *session, int type) {
|
|||||||
static int agent_talk(struct ssh_session_struct *session,
|
static int agent_talk(struct ssh_session_struct *session,
|
||||||
struct ssh_buffer_struct *request, struct ssh_buffer_struct *reply) {
|
struct ssh_buffer_struct *request, struct ssh_buffer_struct *reply) {
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
uint8_t payload[1024] = {0};
|
uint8_t tmpbuf[4];
|
||||||
|
uint8_t *payload = tmpbuf;
|
||||||
|
|
||||||
len = ssh_buffer_get_len(request);
|
len = ssh_buffer_get_len(request);
|
||||||
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
|
SSH_LOG(SSH_LOG_TRACE, "Request length: %u", len);
|
||||||
@@ -287,21 +288,18 @@ static int agent_talk(struct ssh_session_struct *session,
|
|||||||
}
|
}
|
||||||
SSH_LOG(SSH_LOG_TRACE, "Response length: %u", len);
|
SSH_LOG(SSH_LOG_TRACE, "Response length: %u", len);
|
||||||
|
|
||||||
while (len > 0) {
|
payload = ssh_buffer_allocate(reply, len);
|
||||||
size_t n = len;
|
if (payload == NULL) {
|
||||||
if (n > sizeof(payload)) {
|
SSH_LOG(SSH_LOG_WARN, "Not enough space");
|
||||||
n = sizeof(payload);
|
return -1;
|
||||||
}
|
}
|
||||||
if (atomicio(session->agent, payload, n, 1) != n) {
|
|
||||||
SSH_LOG(SSH_LOG_WARN,
|
if (atomicio(session->agent, payload, len, 1) != len) {
|
||||||
"Error reading response from authentication socket.");
|
SSH_LOG(SSH_LOG_WARN,
|
||||||
return -1;
|
"Error reading response from authentication socket.");
|
||||||
}
|
/* Rollback the unused space */
|
||||||
if (ssh_buffer_add_data(reply, payload, n) < 0) {
|
ssh_buffer_pass_bytes_end(reply, len);
|
||||||
SSH_LOG(SSH_LOG_WARN, "Not enough space");
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
len -= n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user