From nobody Wed Sep 06 03:29:53 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RgSYG0xr2z4sZkG; Wed, 6 Sep 2023 03:29:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RgSYF6nqMz4bMd; Wed, 6 Sep 2023 03:29:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693970993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fCkDKXcxz8IvJ65AZXRbk3hbgvBBpmetwc3DBHlGp9s=; b=Cz0Nix1RyFD2S4X0yivwpYDkRZesnvwN94t/UNHWoH3hdtf/fLw3HRFj/q+A57UWGUu0hN Kon9qVfHIn3uPv97d5xxrIIYMu20bR3H455P2uY1q+qJBaJk58vx24DAQJYiqwqCBu7vFR eq+LmN0oZ6vwBBpKIjvNRfG/ukG9dN2xeU3qDtCgHRA2D3wRzCEH5ZLAjYXu+hrC5HOTfi oE+7sdLPs91uM6dvPv8Nvh3WOhKbzBDih7ADlQ4TJNQW8H4bH35tWVZcgvR30hcVCOl+5R aUHSWl+RfumVUShKCxgQC/6IP8KT2zTRk4ieg5ILzTMtQLtLtyiIRmML6Y1y2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693970994; a=rsa-sha256; cv=none; b=Cms6kivCSzj4g8Hjjo1kva1xheFf71zTZhzQhIYiANCFhb5KnPgxaSQJANdzbtZ6lg9n7z TWUs8YWqs8nlP7VwXUDJljJgYXs0vhiOQCZNd07fXmE+6f5s4fciilqzH89vpyRBVPa4Wn PCzC+YJNYvrKGdTuggZmWJPWIegCPjKUFuxc11DlVPZCW8jIEJdq/yOShuNi+NmwNUoJYS Ky8h29+zqoyY4aGijim4h2hqr+gVgX/Bmd/nlYi30F8p5hUuQ/8VJBUr0c4ZUsj5we6bCh yItR495kSGsbFuNr9Mj/sEESJMOn1k8JusuGJfdP1vgY8SFn8GsAcNCbu1WECw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693970993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fCkDKXcxz8IvJ65AZXRbk3hbgvBBpmetwc3DBHlGp9s=; b=VHYebvjnzF0VGEfpc3yfznyANvdyuCHB4x4NwR6RUw38SjyYyKLUa0I78SIyN9aSh8HnkI vgcsO4hRKnf+UqCnsztl75M6RjF2GEz6g9ZASLVRnvn8SaxpWtSmtdaC25VPIq9EPysaWX wI8vP4rYynC4Gsk760UyCKOY3wsvbzA/li/F+Tgv1RifJDw8moZfIpeE9+7HyLZGLg1yg+ QgXwz+eE02Q8dED5w+BKSIMX1O2rK9xWz6LzYXIx8E217dF9QJHCtBXoNejdJObrHa5jVZ ePLqTFQ9OYL0JAJwRIJ1UwPAbIGPHg3oD21c//Ddgzwgx3JUFvVJ4MeiJJfMHw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RgSYF5j8qz10jt; Wed, 6 Sep 2023 03:29:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3863TrEU073371; Wed, 6 Sep 2023 03:29:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3863TrIf073368; Wed, 6 Sep 2023 03:29:53 GMT (envelope-from git) Date: Wed, 6 Sep 2023 03:29:53 GMT Message-Id: <202309060329.3863TrIf073368@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 117c54a78ccd - main - split: Fix linecount parsing. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 117c54a78ccd214c236806721f21da750e512d3e Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=117c54a78ccd214c236806721f21da750e512d3e commit 117c54a78ccd214c236806721f21da750e512d3e Author: Dag-Erling Smørgrav AuthorDate: 2023-09-06 03:28:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-09-06 03:29:31 +0000 split: Fix linecount parsing. The “undocumented kludge” which unfortunately can't be dropped for backward compatibility reasons was prone to segfaulting and would improperly allow a new linecount when one was already set. Fix these issues and add regression tests. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41757 --- usr.bin/split/split.c | 22 ++++++++++------------ usr.bin/split/tests/split_test.sh | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c index 6894e9e63195..af1ed69c9482 100644 --- a/usr.bin/split/split.c +++ b/usr.bin/split/split.c @@ -91,7 +91,7 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); dflag = false; - while ((ch = getopt(argc, argv, "0123456789a:b:cdl:n:p:")) != -1) + while ((ch = getopt(argc, argv, "0::1::2::3::4::5::6::7::8::9::a:b:cdl:n:p:")) != -1) switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -99,17 +99,15 @@ main(int argc, char **argv) * Undocumented kludge: split was originally designed * to take a number after a dash. */ - if (numlines == 0) { - p = argv[optind - 1]; - if (p[0] == '-' && p[1] == ch && !p[2]) - numlines = strtol(++p, &ep, 10); - else - numlines = - strtol(argv[optind] + 1, &ep, 10); - if (numlines <= 0 || *ep) - errx(EX_USAGE, - "%s: illegal line count", optarg); - } + if (numlines != 0) + usage(); + numlines = ch - '0'; + p = optarg ? optarg : ""; + while (numlines >= 0 && *p >= '0' && *p <= '9') + numlines = numlines * 10 + *p++ - '0'; + if (numlines <= 0 || *p != '\0') + errx(EX_USAGE, "%c%s: illegal line count", ch, + optarg ? optarg : ""); break; case 'a': /* Suffix length */ if ((sufflen = strtol(optarg, &ep, 10)) <= 0 || *ep) diff --git a/usr.bin/split/tests/split_test.sh b/usr.bin/split/tests/split_test.sh index 6b59b2442017..c9b87c01618c 100755 --- a/usr.bin/split/tests/split_test.sh +++ b/usr.bin/split/tests/split_test.sh @@ -220,6 +220,25 @@ continue_body() atf_check -o file:input cat xab } +atf_test_case undocumented_kludge +undocumented_kludge_body() +{ + seq 5000 >input + atf_check split -1000 input + atf_check -o file:xae seq 4001 5000 + atf_check split -d1000 input + atf_check -o file:x04 seq 4001 5000 +} + +atf_test_case duplicate_linecount +duplicate_linecount_body() +{ + atf_check -s exit:64 -e ignore split -5 -5 /dev/null + atf_check -s exit:64 -e ignore split -l5 -5 /dev/null + atf_check -s exit:64 -e ignore split -5 -l5 /dev/null + atf_check -s exit:64 -e ignore split -l5 -l5 /dev/null +} + atf_init_test_cases() { atf_add_test_case bytes @@ -231,4 +250,6 @@ atf_init_test_cases() atf_add_test_case pattern atf_add_test_case autoextend atf_add_test_case continue + atf_add_test_case undocumented_kludge + atf_add_test_case duplicate_linecount }