Author: vangyzen Date: Mon May 28 01:58:49 2018 New Revision: 334265 URL: https://svnweb.freebsd.org/changeset/base/334265
Log: tcpdrop: ensure NUL termination of a string strncpy did not guarantee NUL termination of the "stack" string. Use strlcpy instead. While I'm here, avoid unnecessary memset and strnlen calls. Reported by: Coverity CID: 1381035 Sponsored by: Dell EMC Modified: head/usr.sbin/tcpdrop/tcpdrop.c Modified: head/usr.sbin/tcpdrop/tcpdrop.c ============================================================================== --- head/usr.sbin/tcpdrop/tcpdrop.c Mon May 28 00:19:08 2018 (r334264) +++ head/usr.sbin/tcpdrop/tcpdrop.c Mon May 28 01:58:49 2018 (r334265) @@ -73,7 +73,7 @@ main(int argc, char *argv[]) dropall = false; dropallstack = false; - memset(stack, 0, TCP_FUNCTION_NAME_LEN_MAX); + stack[0] = '\0'; state = -1; while ((ch = getopt(argc, argv, "alS:s:")) != -1) { @@ -86,7 +86,7 @@ main(int argc, char *argv[]) break; case 'S': dropallstack = true; - strncpy(stack, optarg, TCP_FUNCTION_NAME_LEN_MAX); + strlcpy(stack, optarg, sizeof(stack)); break; case 's': dropallstack = true; @@ -260,7 +260,7 @@ tcpdropall(const char *stack, int state) continue; /* If requested, skip sockets not having the requested stack. */ - if (strnlen(stack, TCP_FUNCTION_NAME_LEN_MAX) > 0 && + if (stack[0] != '\0' && strncmp(xtp->xt_stack, stack, TCP_FUNCTION_NAME_LEN_MAX)) continue; _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"