summaryrefslogtreecommitdiff
path: root/src/conn-tools
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-16 17:20:08 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-16 17:20:08 +0000
commit6342cffb3485d64340563b9e86d54a667b7148ce (patch)
tree3903f31b8c7d800c0c9c2c471b8d6ad69b62d2e6 /src/conn-tools
parente6c5053c71fe506c59e4717faa8a8aa3a2685ac7 (diff)
downloads6-networking-6342cffb3485d64340563b9e86d54a667b7148ce.tar.xz
Fix missing null terminator
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/conn-tools')
-rw-r--r--src/conn-tools/s6-tcpserverd.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/conn-tools/s6-tcpserverd.c b/src/conn-tools/s6-tcpserverd.c
index 7b42bcc..1cd7007 100644
--- a/src/conn-tools/s6-tcpserverd.c
+++ b/src/conn-tools/s6-tcpserverd.c
@@ -379,26 +379,27 @@ int main (int argc, char const *const *argv)
by_pid = &bypid_info ;
{
- size_t iplen, portlen ;
- char fmtip[IP46_FMT] ;
- char fmtport[UINT16_FMT] ;
+ size_t ippos, portpos, portlen ;
ip46 loc ;
if (socket_local46(0, &loc, &port) == -1)
strerr_diefu1sys(111, "get local socket information") ;
is6 = ip46_is6(&loc) ;
memcpy(ip, loc.ip, is6 ? 16 : 4) ;
- iplen = is6 ? ip6_fmt(fmtip, ip) : ip4_fmt(fmtip, ip) ;
- portlen = uint16_fmt(fmtport, port) ;
- memcpy(modifs + m, fmtip, iplen) ; m += iplen ;
+ ippos = m ;
+ m += is6 ? ip6_fmt(modifs + m, ip) : ip4_fmt(modifs + m, ip) ;
memcpy(modifs + m, "\0TCPLOCALPORT=", 14) ; m += 14 ;
- memcpy(modifs + m, fmtport, portlen) ; m += portlen ;
+ portpos = m ;
+ m += uint16_fmt(modifs + m, port) ;
+ portlen = m - portpos ;
memcpy(modifs + m, "\0TCPREMOTEIP=", 13) ; m += 13 ;
- log_start(fmtip, fmtport) ;
+ log_start(modifs + ippos, modifs + portpos) ;
log_status() ;
if (flag1)
{
+ char fmtport[UINT16_FMT] ;
+ memcpy(fmtport, modifs + portpos, portlen) ;
fmtport[portlen] = '\n' ;
allwrite(1, fmtport, portlen + 1) ;
close(1) ;