1
1

scp: Avoid allocate 8KB stack buffer in ssh_scp_deny_request

since ssh_scp_deny_request is seldom called, let's
utilize malloc to reserve the precise size memory.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Change-Id: I8e7a6d3153cff7691329b9487cd534a7f2887a35
Этот коммит содержится в:
Xiang Xiao 2021-05-13 11:50:37 +08:00
родитель b6b5c59223
Коммит 286a706394

Просмотреть файл

@ -881,7 +881,8 @@ error:
*/
int ssh_scp_deny_request(ssh_scp scp, const char *reason)
{
char buffer[MAX_BUF_SIZE] = {0};
char *buffer = NULL;
size_t len;
int rc;
if (scp == NULL) {
@ -894,8 +895,15 @@ int ssh_scp_deny_request(ssh_scp scp, const char *reason)
return SSH_ERROR;
}
snprintf(buffer, sizeof(buffer), "%c%s\n", 2, reason);
rc = ssh_channel_write(scp->channel, buffer, strlen(buffer));
len = strlen(reason) + 3;
buffer = malloc(len);
if (buffer == NULL) {
return SSH_ERROR;
}
snprintf(buffer, len, "%c%s\n", 2, reason);
rc = ssh_channel_write(scp->channel, buffer, len - 1);
free(buffer);
if (rc == SSH_ERROR) {
return SSH_ERROR;
}