agent_list_identities: Fixed memory leak on OOM
Этот коммит содержится в:
родитель
c00efa5f93
Коммит
08973a00a1
21
src/agent.c
21
src/agent.c
@ -537,18 +537,17 @@ agent_list_identities(LIBSSH2_AGENT *agent)
|
|||||||
struct agent_publickey *identity;
|
struct agent_publickey *identity;
|
||||||
ssize_t comment_len;
|
ssize_t comment_len;
|
||||||
|
|
||||||
identity = LIBSSH2_ALLOC(agent->session, sizeof *identity);
|
|
||||||
if (!identity) {
|
|
||||||
rc = LIBSSH2_ERROR_ALLOC;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the length of the blob */
|
/* Read the length of the blob */
|
||||||
len -= 4;
|
len -= 4;
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
identity = LIBSSH2_ALLOC(agent->session, sizeof *identity);
|
||||||
|
if (!identity) {
|
||||||
|
rc = LIBSSH2_ERROR_ALLOC;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
identity->external.blob_len = _libssh2_ntohu32(s);
|
identity->external.blob_len = _libssh2_ntohu32(s);
|
||||||
s += 4;
|
s += 4;
|
||||||
|
|
||||||
@ -556,12 +555,15 @@ agent_list_identities(LIBSSH2_AGENT *agent)
|
|||||||
len -= identity->external.blob_len;
|
len -= identity->external.blob_len;
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||||
|
LIBSSH2_FREE(agent->session, identity);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
identity->external.blob = LIBSSH2_ALLOC(agent->session,
|
identity->external.blob = LIBSSH2_ALLOC(agent->session,
|
||||||
identity->external.blob_len);
|
identity->external.blob_len);
|
||||||
if (!identity->external.blob) {
|
if (!identity->external.blob) {
|
||||||
rc = LIBSSH2_ERROR_ALLOC;
|
rc = LIBSSH2_ERROR_ALLOC;
|
||||||
|
LIBSSH2_FREE(agent->session, identity);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
memcpy(identity->external.blob, s, identity->external.blob_len);
|
memcpy(identity->external.blob, s, identity->external.blob_len);
|
||||||
@ -571,6 +573,8 @@ agent_list_identities(LIBSSH2_AGENT *agent)
|
|||||||
len -= 4;
|
len -= 4;
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||||
|
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||||
|
LIBSSH2_FREE(agent->session, identity);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
comment_len = _libssh2_ntohu32(s);
|
comment_len = _libssh2_ntohu32(s);
|
||||||
@ -580,12 +584,17 @@ agent_list_identities(LIBSSH2_AGENT *agent)
|
|||||||
len -= comment_len;
|
len -= comment_len;
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||||
|
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||||
|
LIBSSH2_FREE(agent->session, identity);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
identity->external.comment = LIBSSH2_ALLOC(agent->session,
|
identity->external.comment = LIBSSH2_ALLOC(agent->session,
|
||||||
comment_len + 1);
|
comment_len + 1);
|
||||||
if (!identity->external.comment) {
|
if (!identity->external.comment) {
|
||||||
rc = LIBSSH2_ERROR_ALLOC;
|
rc = LIBSSH2_ERROR_ALLOC;
|
||||||
|
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||||
|
LIBSSH2_FREE(agent->session, identity);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
identity->external.comment[comment_len] = '\0';
|
identity->external.comment[comment_len] = '\0';
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user