Add a placehohlder for non-expanded identities

Expanding a string twice could lead to unwanted behaviour.
This solution creates a ssh_list (`opts.identites_non_exp`) to store the strings
before expansion and by using ssh_apply it moves the string to the
`opts.identities`. This way the expanded strings are separated.

Signed-off-by: Norbert Pocs <npocs@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Norbert Pocs
2022-11-16 10:40:38 +01:00
committed by Jakub Jelen
parent 435f1549f1
commit 1ff893c914
3 changed files with 75 additions and 35 deletions

View File

@@ -119,13 +119,17 @@ ssh_session ssh_new(void)
if (session->opts.identity == NULL) {
goto err;
}
session->opts.identity_non_exp = ssh_list_new();
if (session->opts.identity_non_exp == NULL) {
goto err;
}
id = strdup("%d/id_ed25519");
if (id == NULL) {
goto err;
}
rc = ssh_list_append(session->opts.identity, id);
rc = ssh_list_append(session->opts.identity_non_exp, id);
if (rc == SSH_ERROR) {
goto err;
}
@@ -135,7 +139,7 @@ ssh_session ssh_new(void)
if (id == NULL) {
goto err;
}
rc = ssh_list_append(session->opts.identity, id);
rc = ssh_list_append(session->opts.identity_non_exp, id);
if (rc == SSH_ERROR) {
goto err;
}
@@ -145,7 +149,7 @@ ssh_session ssh_new(void)
if (id == NULL) {
goto err;
}
rc = ssh_list_append(session->opts.identity, id);
rc = ssh_list_append(session->opts.identity_non_exp, id);
if (rc == SSH_ERROR) {
goto err;
}
@@ -155,7 +159,7 @@ ssh_session ssh_new(void)
if (id == NULL) {
goto err;
}
rc = ssh_list_append(session->opts.identity, id);
rc = ssh_list_append(session->opts.identity_non_exp, id);
if (rc == SSH_ERROR) {
goto err;
}
@@ -285,6 +289,17 @@ void ssh_free(ssh_session session)
ssh_list_free(session->opts.identity);
}
if (session->opts.identity_non_exp) {
char *id;
for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
id != NULL;
id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
SAFE_FREE(id);
}
ssh_list_free(session->opts.identity_non_exp);
}
while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
session->out_queue)) != NULL) {
SSH_BUFFER_FREE(b);