aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2026-06-05 21:04:26 +1000
committerDavid Gibson <david@gibson.dropbear.id.au>2026-06-09 12:18:40 +1000
commitd71e04013af0f449effcf2ec18235f6e1d1cbf5c (patch)
treefda9eab379c27b516307f1c4c8c833566bfcf6da
parentb2787350eab2a69d90a583dbc5a648b8c6cbf15b (diff)
downloadpasst-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar.gz
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar.bz2
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar.lz
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar.xz
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.tar.zst
passt-d71e04013af0f449effcf2ec18235f6e1d1cbf5c.zip
flow: Safer errno handling in flowside_connect() callers
flowside_connect() behaves much like connect(2) itself, returning -1 on error with errno set to the error code. One of the callers, in udp_flow_sock(), uses the errno code with flow_dbg_perror() *after* it's called epoll_del() and close() either of which could clobber errno. Change flowside_connect() to use the more regular convention for internal functions: return a negative errno code on error, rather than just -1. Save it in the callers and use that rather than raw errno to print the message. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--flow.c6
-rw-r--r--tcp.c4
-rw-r--r--udp_flow.c7
3 files changed, 9 insertions, 8 deletions
diff --git a/flow.c b/flow.c
index dd92bad..9882843 100644
--- a/flow.c
+++ b/flow.c
@@ -259,7 +259,7 @@ int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif,
*
* Connect @s to the endpoint address and port from @tgt.
*
- * Return: 0 on success, negative on error
+ * Return: 0 on success, negative error code on error
*/
int flowside_connect(const struct ctx *c, int s,
uint8_t pif, const struct flowside *tgt)
@@ -267,7 +267,9 @@ int flowside_connect(const struct ctx *c, int s,
union sockaddr_inany sa;
pif_sockaddr(c, &sa, pif, &tgt->eaddr, tgt->eport);
- return connect(s, &sa.sa, socklen_inany(&sa));
+ if (connect(s, &sa.sa, socklen_inany(&sa)) < 0)
+ return -errno;
+ return 0;
}
/** flow_log__ - Log flow-related message, internal helper
diff --git a/tcp.c b/tcp.c
index 6fba865..8181364 100644
--- a/tcp.c
+++ b/tcp.c
@@ -3744,8 +3744,8 @@ static int tcp_flow_repair_connect(const struct ctx *c,
rc = flowside_connect(c, conn->sock, PIF_HOST, tgt);
if (rc) {
- rc = -errno;
- flow_perror(conn, "Failed to connect migrated socket");
+ flow_err(conn, "Failed to connect migrated socket: %s",
+ strerror_(-rc));
return rc;
}
diff --git a/udp_flow.c b/udp_flow.c
index 35417bc..6edfa65 100644
--- a/udp_flow.c
+++ b/udp_flow.c
@@ -88,13 +88,12 @@ static int udp_flow_sock(const struct ctx *c,
return rc;
}
- if (flowside_connect(c, s, pif, side) < 0) {
- rc = -errno;
-
+ if ((rc = flowside_connect(c, s, pif, side)) < 0) {
epoll_del(flow_epollfd(&uflow->f), s);
close(s);
- flow_dbg_perror(uflow, "Couldn't connect flow socket");
+ flow_dbg(uflow, "Couldn't connect flow socket: %s",
+ strerror_(-rc));
return rc;
}
uflow->s[sidei] = s;