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

src: prevent name clashes with POSIX functions

Avoid using names for internal function pointers that happen to be POSIX
or other system functions. To improve readability and to avoid issues
when the standard symbols are macros or need to be redefined. E.g. as
`connect()` is in OS/400 builds.

Also:
- agent: drop intermediate, single-use typedefs, while there.

Reported-by: Patrick Monnerat
Bug: https://github.com/libssh2/libssh2/pull/2668#issue-5849108984

Closes #2674
This commit is contained in:
Viktor Szakats
2026-10-15 01:38:43 +02:00
parent 83284a05a1
commit 7db5e204d9
3 changed files with 20 additions and 23 deletions

View File

@@ -104,11 +104,6 @@ struct agent_transaction_ctx {
size_t send_recv_total;
};
typedef int (*agent_connect_func)(LIBSSH2_AGENT *agent);
typedef int (*agent_transact_func)(LIBSSH2_AGENT *agent,
struct agent_transaction_ctx *transctx);
typedef int (*agent_disconnect_func)(LIBSSH2_AGENT *agent);
struct agent_publickey {
struct list_node node;
@@ -117,9 +112,11 @@ struct agent_publickey {
};
struct agent_ops {
const agent_connect_func connect;
const agent_transact_func transact;
const agent_disconnect_func disconnect;
int (*connect_it)(LIBSSH2_AGENT *agent); /* prevent name clash with
POSIX connect() */
int (*transact)(LIBSSH2_AGENT *agent,
struct agent_transaction_ctx *transctx);
int (*disconnect)(LIBSSH2_AGENT *agent);
};
struct _LIBSSH2_AGENT {
@@ -654,7 +651,7 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
/* Send the length of the request */
if(transctx->state == agent_NB_state_request_created) {
ssh2_htonu32(buf, (uint32_t)transctx->request_len);
rc = (int)agent_send_all(agent->session->send, agent->fd,
rc = (int)agent_send_all(agent->session->send_cb, agent->fd,
buf, sizeof(buf), 0,
&agent->session->abstract);
if(rc == -EAGAIN)
@@ -667,7 +664,7 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
/* Send the request body */
if(transctx->state == agent_NB_state_request_length_sent) {
rc = (int)agent_send_all(agent->session->send, agent->fd,
rc = (int)agent_send_all(agent->session->send_cb, agent->fd,
transctx->request, transctx->request_len, 0,
&agent->session->abstract);
if(rc == -EAGAIN)
@@ -680,7 +677,7 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
/* Receive the length of the response */
if(transctx->state == agent_NB_state_request_sent) {
rc = (int)agent_recv_all(agent->session->recv, agent->fd,
rc = (int)agent_recv_all(agent->session->recv_cb, agent->fd,
buf, sizeof(buf), 0,
&agent->session->abstract);
if(rc < 0) {
@@ -705,7 +702,7 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
/* Receive the response body */
if(transctx->state == agent_NB_state_response_length_received) {
rc = (int)agent_recv_all(agent->session->recv, agent->fd,
rc = (int)agent_recv_all(agent->session->recv_cb, agent->fd,
transctx->response, transctx->response_len, 0,
&agent->session->abstract);
if(rc < 0) {
@@ -1135,7 +1132,7 @@ int libssh2_agent_connect(LIBSSH2_AGENT *agent)
for(i = 0; agent_supported_backends[i].name; i++) {
agent->ops = agent_supported_backends[i].ops;
rc = agent->ops->connect(agent);
rc = agent->ops->connect_it(agent);
if(!rc)
return LIBSSH2_ERROR_NONE;
}

View File

@@ -274,9 +274,9 @@ struct iovec {
channel, &(channel)->abstract)
#define SSH2_SEND_FD(session, fd, buffer, length, flags) \
((session)->send)(fd, buffer, length, flags, &(session)->abstract)
(session)->send_cb(fd, buffer, length, flags, &(session)->abstract)
#define SSH2_RECV_FD(session, fd, buffer, length, flags) \
((session)->recv)(fd, buffer, length, flags, &(session)->abstract)
(session)->recv_cb(fd, buffer, length, flags, &(session)->abstract)
#define SSH2_SEND(session, buffer, length, flags) \
SSH2_SEND_FD(session, (session)->socket_fd, buffer, length, flags)
@@ -716,8 +716,8 @@ struct _LIBSSH2_SESSION {
LIBSSH2_AUTHAGENT_FUNC(*authagent);
LIBSSH2_ADD_IDENTITIES_FUNC(*addLocalIdentities);
LIBSSH2_AUTHAGENT_SIGN_FUNC(*agentSignCallback);
LIBSSH2_SEND_FUNC(*send);
LIBSSH2_RECV_FUNC(*recv);
LIBSSH2_SEND_FUNC(*send_cb); /* prevent name clash with POSIX send() */
LIBSSH2_RECV_FUNC(*recv_cb); /* prevent name clash with POSIX recv() */
/* Method preferences -- NULL yields "load order" */
char *kex_prefs;

View File

@@ -409,8 +409,8 @@ LIBSSH2_SESSION *libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC(*my_alloc),
session->alloc = local_alloc;
session->free = local_free;
session->realloc = local_realloc;
session->send = ssh2_send;
session->recv = ssh2_recv;
session->send_cb = ssh2_send;
session->recv_cb = ssh2_recv;
session->abstract = abstract;
session->api_timeout_ms = 0; /* timeout-free API by default */
session->api_block_mode = 1; /* blocking API by default */
@@ -472,13 +472,13 @@ libssh2_cb_generic *libssh2_session_callback_set2(LIBSSH2_SESSION *session,
return oldcb;
case LIBSSH2_CALLBACK_SEND:
oldcb = (libssh2_cb_generic *)session->send;
session->send = (LIBSSH2_SEND_FUNC(*))callback;
oldcb = (libssh2_cb_generic *)session->send_cb;
session->send_cb = (LIBSSH2_SEND_FUNC(*))callback;
return oldcb;
case LIBSSH2_CALLBACK_RECV:
oldcb = (libssh2_cb_generic *)session->recv;
session->recv = (LIBSSH2_RECV_FUNC(*))callback;
oldcb = (libssh2_cb_generic *)session->recv_cb;
session->recv_cb = (LIBSSH2_RECV_FUNC(*))callback;
return oldcb;
case LIBSSH2_CALLBACK_AUTHAGENT: