Skip to content

Commit

Permalink
socket: skt_tcp_stat_text() always return used buf size.
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhuk-im committed Apr 29, 2024
1 parent dea7b69 commit 41326c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ skt_tcp_stat_text(uintptr_t skt, const char *tabs,

optlen = sizeof(info);
memset(&info, 0x00, sizeof(info));
if (0 != getsockopt((int)skt, IPPROTO_TCP, TCP_INFO, &info, &optlen))
if (0 != getsockopt((int)skt, IPPROTO_TCP, TCP_INFO, &info, &optlen)) {
(*buf_size_ret) = 0;
return (errno);
}
if (10 < info.tcpi_state) {
info.tcpi_state = 11; /* UNKNOWN */
}
Expand All @@ -858,8 +860,10 @@ skt_tcp_stat_text(uintptr_t skt, const char *tabs,
continue;
topts_used += strlcpy((topts + topts_used),
tcpi_options_flags_str[i], (sizeof(topts) - topts_used));
if ((sizeof(topts) - 2) < topts_used)
if ((sizeof(topts) - 2) < topts_used) {
(*buf_size_ret) = topts_used;
return (ENOSPC);
}
topts[topts_used ++] = ' ';
}
/* Remove trailing space and make sure that 0x00 at the end of string. */
Expand Down Expand Up @@ -956,8 +960,10 @@ skt_tcp_stat_text(uintptr_t skt, const char *tabs,
);
#endif /* Linux specific code. */

if (0 > rc) /* Error. */
if (0 > rc) { /* Error. */
(*buf_size_ret) = 0;
return (EFAULT);
}
(*buf_size_ret) = (size_t)rc;
if (buf_size <= (size_t)rc) /* Truncated. */
return (ENOSPC);
Expand Down

0 comments on commit 41326c3

Please sign in to comment.