Skip to content

Commit 4aa1720

Browse files
committed
agent: do not store stack pointer in transaction context
Fixing: ``` src/agent.c:956:9: warning: Address of stack memory associated with local variable 'c' is still referred to by the caller variable 'agent' upon returning to the caller. This will be a dangling reference [clang-analyzer-core.StackAddressEscape] 956 | return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE, | ^ src/agent.c:1164:12: note: Calling 'agent_list_identities' 1164 | return agent_list_identities(agent); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/agent.c:942:8: note: Assuming field 'state' is equal to agent_NB_state_init 942 | if(transctx->state == agent_NB_state_init) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/agent.c:942:5: note: Taking true branch 942 | if(transctx->state == agent_NB_state_init) { | ^ src/agent.c:950:5: note: Taking false branch 950 | if(*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES) | ^ src/agent.c:954:8: note: Assuming field 'ops' is null 954 | if(!agent->ops) | ^~~~~~~~~~~ src/agent.c:954:5: note: Taking true branch 954 | if(!agent->ops) | ^ ``` Closes libssh2#1845
1 parent 3d4ff6b commit 4aa1720

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/agent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,11 @@ agent_list_identities(LIBSSH2_AGENT *agent)
934934
ssize_t len, num_identities;
935935
unsigned char *s;
936936
int rc;
937-
unsigned char c = SSH2_AGENTC_REQUEST_IDENTITIES;
937+
static const unsigned char c = SSH2_AGENTC_REQUEST_IDENTITIES;
938938

939939
/* Create a request to list identities */
940940
if(transctx->state == agent_NB_state_init) {
941-
transctx->request = &c;
941+
transctx->request = LIBSSH2_UNCONST(&c);
942942
transctx->request_len = 1;
943943
transctx->send_recv_total = 0;
944944
transctx->state = agent_NB_state_request_created;

0 commit comments

Comments
 (0)