git: e2279d5ba9a9 - main - tcpdrop: improve handling of -C and -S
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 Oct 2026 19:14:59 UTC
The branch main has been updated by tuexen:
URL: https://cgit.FreeBSD.org/src/commit/?id=e2279d5ba9a91407239cba4bed80abff73b15798
commit e2279d5ba9a91407239cba4bed80abff73b15798
Author: Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2026-10-01 19:09:11 +0000
Commit: Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-10-01 19:14:11 +0000
tcpdrop: improve handling of -C and -S
Handle empty strings for -Cand -S correctly.
Reported by: maxim
Reviewed by: maxim
MFC after: 1 week
MFC to: stable/14
MFC to: stable/15
Sponsored by: Netflix, Inc.
Differential Revision: https://reviews.freebsd.org/D60210
---
usr.sbin/tcpdrop/tcpdrop.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/usr.sbin/tcpdrop/tcpdrop.c b/usr.sbin/tcpdrop/tcpdrop.c
index 6f6b94789df1..00404cb98794 100644
--- a/usr.sbin/tcpdrop/tcpdrop.c
+++ b/usr.sbin/tcpdrop/tcpdrop.c
@@ -63,16 +63,16 @@ static void usage(void) __dead2;
int
main(int argc, char *argv[])
{
- char stack[TCP_FUNCTION_NAME_LEN_MAX];
- char ca_name[TCP_CA_NAME_MAX];
- char *lport, *fport;
+ char stack_buf[TCP_FUNCTION_NAME_LEN_MAX];
+ char ca_name_buf[TCP_CA_NAME_MAX];
+ char *stack, *ca_name, *lport, *fport;
bool dropall, dropspecific;
int ch, state;
dropall = false;
dropspecific = false;
- ca_name[0] = '\0';
- stack[0] = '\0';
+ ca_name = NULL;
+ stack = NULL;
state = -1;
while ((ch = getopt(argc, argv, "aC:lS:s:")) != -1) {
@@ -82,14 +82,16 @@ main(int argc, char *argv[])
break;
case 'C':
dropspecific = true;
- strlcpy(ca_name, optarg, sizeof(ca_name));
+ strlcpy(ca_name_buf, optarg, sizeof(ca_name_buf));
+ ca_name = ca_name_buf;
break;
case 'l':
tcpdrop_list_commands = true;
break;
case 'S':
dropspecific = true;
- strlcpy(stack, optarg, sizeof(stack));
+ strlcpy(stack_buf, optarg, sizeof(stack_buf));
+ stack = stack_buf;
break;
case 's':
dropspecific = true;
@@ -266,12 +268,12 @@ tcpdropall(const char *ca_name, const char *stack, int state)
* If requested, skip sockets not having the requested
* congestion control algorithm.
*/
- if (ca_name[0] != '\0' &&
+ if (ca_name != NULL &&
strncmp(xtp->xt_cc, ca_name, TCP_CA_NAME_MAX))
continue;
/* If requested, skip sockets not having the requested stack. */
- if (stack[0] != '\0' &&
+ if (stack != NULL &&
strncmp(xtp->xt_stack, stack, TCP_FUNCTION_NAME_LEN_MAX))
continue;