1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00

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 #1845
This commit is contained in:
Viktor Szakats
2026-04-10 11:38:40 +02:00
parent 3d4ff6b240
commit 4aa1720b60

View File

@@ -934,11 +934,11 @@ agent_list_identities(LIBSSH2_AGENT *agent)
ssize_t len, num_identities;
unsigned char *s;
int rc;
unsigned char c = SSH2_AGENTC_REQUEST_IDENTITIES;
static const unsigned char c = SSH2_AGENTC_REQUEST_IDENTITIES;
/* Create a request to list identities */
if(transctx->state == agent_NB_state_init) {
transctx->request = &c;
transctx->request = LIBSSH2_UNCONST(&c);
transctx->request_len = 1;
transctx->send_recv_total = 0;
transctx->state = agent_NB_state_request_created;