From nobody Thu Sep 14 15:00:34 2023 X-Original-To: dev-commits-src-all@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 4RmgVV6mMMz4sbCY; Thu, 14 Sep 2023 15:00:34 +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 4RmgVV5LW3z4WTt; Thu, 14 Sep 2023 15:00:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694703634; 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=obhor7Xq6yHVwil8PqMXFrK6QJVSkUj/vw9t39JqAUI=; b=h/PtT7DjKs/hJc2yuxg9IzGOdwubH8xlFMId/wdyeMK/0u/eqDrVGL6dit0z42EmVHD8WV K/0YCP1ptVkheDxm7y08BpGqPnHkA3RS2uSKoslPn7dq5jpTZLPFemaLBhFJ97BCmVN7Xv m6NKdXnMvMNa371qaKITb3zv3xxcOJIVCrbGvOdHTrsKzp/xk2DpA9aiaJ9jwbYK48M+zR i3tG9LC1Bz4qjPCtZwokhgzhFcF3I4s/P6hcU4o4wIBU7Zdv9Vhx+JUZwDuexw7L/+TGfy Q0CvBgHufyv9qXP2cLnRglS3o3s63NmMBJ35G2IplkDSRVNu3FWilpfCxiNcRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694703634; a=rsa-sha256; cv=none; b=YAggUVf/j/pRqHaBkMZJCVd+vLWNR+uKUvaeOc+A09tojbGwNXPSiGNboJaCqkcre2lxo1 zYjdI8FwkV0+Km+wQ3Eg1poiovvuQ1LtvBX15SS0Icp5/wpTt1vHYW/j6zRiBeXA2nXoM+ ccgnwjenGlmYR1ynJqW4T6ncVTvn/twTH/mBtm8e23obHt+8zy0DMTdny7TMvMCr8snPy1 d56LMNMFdQ+oTkE8UW6RsasEaN6HvoD0Dzw4zbWr3cMcWnpZjncqvUgM4MIkwcCGw7kH1p UlyUhN7XhcIR8zQB9HeAeag+9mjmjMvMVhBaJuAkkGE4A/wR9ViN95MZdrOdhw== 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=1694703634; 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=obhor7Xq6yHVwil8PqMXFrK6QJVSkUj/vw9t39JqAUI=; b=ZkOw3WClWTm/YNdf6Lw90OOdvKN4OdkEQ/WqnBknG5UyX9ofYLIsmULTdi38/UPENaIwzL m3o59bZtvA29m27agHFinotNWGv5VtivbUU4/Ymg0WCDI/gQf+w0JKUryKtaf4kNLaBj0m qmbPMJlUdliHk34WX1wFi0u+D6OZmKvlWBYlr/jcQgG2k4FrFJ7s0K9y36OGyDG9e/wo+6 TITUYvj7ElTfhODYyFV/ikGfmRjFOJWXMDWIkKF9pyLYHUKDF0VxYbMOWmiH27yhq9rkM5 RHeFbFVy3JLdiXenKQ2b7p9L/CNjcGZTuUD4oOXjcAvv/aasKMkhy40vf2JCFg== 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 4RmgVV4RqGz11c6; Thu, 14 Sep 2023 15:00:34 +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 38EF0YaG089597; Thu, 14 Sep 2023 15:00:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38EF0YBU089594; Thu, 14 Sep 2023 15:00:34 GMT (envelope-from git) Date: Thu, 14 Sep 2023 15:00:34 GMT Message-Id: <202309141500.38EF0YBU089594@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e035e58097ae - stable/13 - split: Add missing test cases. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: e035e58097ae6e7fbdf4934c65752baf3f6ab7d3 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e035e58097ae6e7fbdf4934c65752baf3f6ab7d3 commit e035e58097ae6e7fbdf4934c65752baf3f6ab7d3 Author: Dag-Erling Smørgrav AuthorDate: 2023-09-06 03:28:19 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-09-14 14:59:52 +0000 split: Add missing test cases. This adds test cases for c4f7198f47c1 and ac17fc816e67. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41755 (cherry picked from commit cbea5eddb1b6ae2a101beacf00bf165517f4f2b1) split: Code cleanup. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41756 (cherry picked from commit 851bf856d1a7ad5427ea9c22639ab6f6c4a3f503) 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 (cherry picked from commit 117c54a78ccd214c236806721f21da750e512d3e) --- usr.bin/split/split.c | 45 ++++++++++++++++++++------------------- usr.bin/split/tests/split_test.sh | 45 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 23 deletions(-) diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c index b5a457ab6ecd..af1ed69c9482 100644 --- a/usr.bin/split/split.c +++ b/usr.bin/split/split.c @@ -41,7 +41,6 @@ static const char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; #endif #include -#include #include #include @@ -85,14 +84,14 @@ static void usage(void) __dead2; int main(int argc, char **argv) { - int ch; - int error; - char *ep, *p; + const char *p; + char *ep; + int ch, error; 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': @@ -100,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) @@ -157,17 +154,22 @@ main(int argc, char **argv) argv += optind; argc -= optind; - if (*argv != NULL) { /* Input file. */ + if (argc > 0) { /* Input file. */ if (strcmp(*argv, "-") == 0) ifd = STDIN_FILENO; else if ((ifd = open(*argv, O_RDONLY, 0)) < 0) err(EX_NOINPUT, "%s", *argv); ++argv; + --argc; + } + if (argc > 0) { /* File name prefix. */ + if (strlcpy(fname, *argv, sizeof(fname)) >= sizeof(fname)) + errx(EX_USAGE, "file name prefix is too long: %s", + *argv); + ++argv; + --argc; } - if (*argv != NULL) /* File name prefix. */ - if (strlcpy(fname, *argv++, sizeof(fname)) >= sizeof(fname)) - errx(EX_USAGE, "file name prefix is too long"); - if (*argv != NULL) + if (argc > 0) usage(); if (strlen(fname) + (unsigned long)sufflen >= sizeof(fname)) @@ -400,7 +402,6 @@ newfile(void) sufflen++; /* Reset so we start back at all 'a's in our extended suffix. */ - tfnum = 0; fnum = 0; } diff --git a/usr.bin/split/tests/split_test.sh b/usr.bin/split/tests/split_test.sh index 899fd028e74b..c9b87c01618c 100755 --- a/usr.bin/split/tests/split_test.sh +++ b/usr.bin/split/tests/split_test.sh @@ -1,7 +1,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (c) 2022 Klara Systems +# Copyright (c) 2022-2023 Klara Systems # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -200,6 +200,45 @@ EOF atf_check -o file:foo-ab cat split-ab } +atf_test_case autoextend +autoextend_body() +{ + seq $((26*25+1)) >input + atf_check split -l1 input + atf_check -o inline:"$((26*25))\n" cat xyz + atf_check -o inline:"$((26*25+1))\n" cat xzaaa +} + +atf_test_case continue +continue_body() +{ + echo hello >input + atf_check split input + atf_check -o file:input cat xaa + atf_check -s exit:1 -e ignore cat xab + atf_check split -c input + 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 @@ -209,4 +248,8 @@ atf_init_test_cases() atf_add_test_case numeric_suffix atf_add_test_case larger_suffix_length 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 }