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
Этот коммит содержится в:
родитель
b6b5c59223
Коммит
286a706394
14
src/scp.c
14
src/scp.c
@ -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;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user