From nobody Fri Nov 14 14:29:08 2025 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 4d7KJh5pBxz6GWG3; Fri, 14 Nov 2025 14:29:08 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d7KJh51Z1z3QQ0; Fri, 14 Nov 2025 14:29:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763130548; 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=JbcpeRc2U62p36tVsIvAtnDzq0bmr3GsGsBhHsEu7Xw=; b=V8IohVnd/4+cjRfCUoeIXUXqqdgfKFK3SeiCVoOXXk6s4CgWDpNsMSM7Np1rk+uOrxp72o hfA0ZKykj2qOyuRSOOrdaEoGX/NAjuVDu52UiDtGdwlHGy0aLQeiaXZhtFVxwMQU1iw/cK uChUa9ecr0QjTLKQDV1ojYhmkqnoPyOx5uN0HvIoNGKYfTs/UnT7TiG1bi3xKRdFODHBQw SMA2obZLhfp0OeHVLuhIuwv6razC1j3RJ+LLZIVVq+XqJLfUX7hKMlL3UtDe/mUIsVOhVS 27n46BCgN04NyvmE9F266AdRfAudfAvrGjWdClJCWCEiLUixKWjocEXAiETZbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763130548; 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=JbcpeRc2U62p36tVsIvAtnDzq0bmr3GsGsBhHsEu7Xw=; b=k5XVWUODZfKaWjC5LdqEpIjluFjUpHawMCeshMezfQgL4hWewng1GMLlOWUpmGaQYE94Nk KxiMnReWmQo3yB8wPIRQrFmMVQHFKhLrzYyEWb42D/5ll9Wvq/NgJFgiLrw7twZVZz2SBP 5xJ0ZY1U35AnWvxvEWAXIql63/TWGwlo8/CaRehUDQcfbMQKv8xZ9ZQf5NajUy7/1Z9gAH mQVEHhO1tNx7x3pixExnpo1YIVIe+WXvlPeQT2HIppN/MELUjYv36e9TTWsDwn4F1wtwPd D4V4vNbXlgSQDijM9COZsW9WKRdx9IqX2BVjkDSIjLYj4Q4rDaeFOZsarG5u5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763130548; a=rsa-sha256; cv=none; b=Y+lpfmY64ZQjGE34WHA4Q9ngtQ3PHfjpwxrD55q6huVni3w8+Tlz1n2IUKYfggZz+1bZFO PhfO6pWLUhjSw5FE57KPgj6b8NQuz6KkyBCTs1tM+L/app6RM9Pr2YUmkL9iAfQrbuqA0S B/Xiw89pUTdowU8Ks5CL4btQPArrozckYyKbGi6wGNkFb0fmBkARj2fQh0GcKbHSOGGArf Q1c1+sRuex4+YIp/eJIFo1bZEt0A1Id2JSL864Ssfgt1v0swjd+f6OIg/7/yjhXUFspTAJ ZLE+R9pFk9Xo3uxz0TXM72aIaumiNY/azJ17RbS+8y2QlHM4lzuL5Hi4b9rg9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4d7KJh4Yyvz198K; Fri, 14 Nov 2025 14:29:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5AEET82f039049; Fri, 14 Nov 2025 14:29:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AEET8pU039046; Fri, 14 Nov 2025 14:29:08 GMT (envelope-from git) Date: Fri, 14 Nov 2025 14:29:08 GMT Message-Id: <202511141429.5AEET8pU039046@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: fa272a527686 - main - quot: Rewrite -n mode input parser 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-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: fa272a5276865a97b01823fe6546940eaaf1b164 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=fa272a5276865a97b01823fe6546940eaaf1b164 commit fa272a5276865a97b01823fe6546940eaaf1b164 Author: Dag-Erling Smørgrav AuthorDate: 2025-11-14 14:28:40 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-11-14 14:29:05 +0000 quot: Rewrite -n mode input parser The existing parser was needlessly complicated and wildly inconsistent in how it handled invalid input. Rewrite using getline() and treat invalid input consistently: silently ignore lines that don't begin with a number, and print a warning if the inode number is out of range. PR: 290992 MFC after: 1 week Reviewed by: obrien Differential Revision: https://reviews.freebsd.org/D53726 --- usr.sbin/quot/quot.8 | 3 ++- usr.sbin/quot/quot.c | 47 +++++++++++++++++++++------------------- usr.sbin/quot/tests/quot_test.sh | 19 ++++++++++++++++ 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/usr.sbin/quot/quot.8 b/usr.sbin/quot/quot.8 index 32e666e2a863..69c0a2d84b9b 100644 --- a/usr.sbin/quot/quot.8 +++ b/usr.sbin/quot/quot.8 @@ -27,7 +27,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 15, 2025 +.Dd November 13, 2025 .Dt QUOT 8 .Os .Sh NAME @@ -60,6 +60,7 @@ By default, all sizes are reported in 512-byte block counts. Given a list of inodes (plus some optional data on each line) in the standard input, for each file print out the owner (plus the remainder of the input line). +Lines that do not begin with a number are ignored. This is traditionally used in the pipe: .Bd -literal -offset indent diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 5dda36ac8499..d2f7646f7041 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -390,41 +391,43 @@ douser(int fd, struct fs *super) static void donames(int fd, struct fs *super) { - int c; - ino_t maxino; - uintmax_t inode; union dinode *dp; + char *end, *line; + size_t cap; + ssize_t len; + intmax_t inode, maxino; maxino = super->fs_ncg * super->fs_ipg - 1; - /* first skip the name of the filesystem */ - while ((c = getchar()) != EOF && (c < '0' || c > '9')) - while ((c = getchar()) != EOF && c != '\n'); - ungetc(c, stdin); - while (scanf("%ju", &inode) == 1) { - if (inode > maxino) { - warnx("illegal inode %ju", inode); - return; + line = NULL; + cap = 0; + while ((len = getline(&line, &cap, stdin)) > 0) { + if (len > 0 && line[len - 1] == '\n') + line[--len] = '\0'; + inode = strtoimax(line, &end, 10); + /* + * Silently ignore lines that do not begin with a number. + * For backward compatibility reasons, we do not require + * the optional comment to be preceded by whitespace. + */ + if (end == line) + continue; + if (inode <= 0 || inode > maxino) { + warnx("invalid inode %jd", inode); + continue; } if ((dp = get_inode(fd, super, inode)) != NULL && !isfree(super, dp)) { printf("%s\t", user(DIP(super, dp, di_uid))->name); /* now skip whitespace */ - while ((c = getchar()) == ' ' || c == '\t') - /* nothing */; + while (*end == ' ' || *end == '\t') + end++; /* and print out the remainder of the input line */ - while (c != EOF && c != '\n') { - putchar(c); - c = getchar(); - } - putchar('\n'); + printf("%s\n", end); } else { /* skip this line */ - while ((c = getchar()) != EOF && c != '\n') - /* nothing */; } - if (c == EOF) - break; } + free(line); } static void diff --git a/usr.sbin/quot/tests/quot_test.sh b/usr.sbin/quot/tests/quot_test.sh index 21088d162a53..c5e6717adca1 100644 --- a/usr.sbin/quot/tests/quot_test.sh +++ b/usr.sbin/quot/tests/quot_test.sh @@ -15,6 +15,8 @@ quot_setup() atf_check mount /dev/$dev "$mnt" echo "/dev/$dev: ($mnt)" >expect printf "%5d\t%5d\t%-8s\n" 8 2 "#0" >>expect + printf "%s\n" "/dev/$dev" >ninput + echo "/dev/$dev: ($mnt)" >nexpect } # Create a directory owned by a given UID @@ -23,12 +25,25 @@ quot_adduid() local uid=$1 atf_check install -d -o $uid -g 0 mnt/$uid printf "%5d\t%5d\t%-8s\n" 4 1 "#$uid" >>expect + ls -di mnt/$uid >>ninput + printf "%s\t%s\n" "#$uid" mnt/$uid >>nexpect } # Perform the tests quot_test() { local dev=$(cat dev) + # Deliberately add invalid lines to our -n input before the + # valid ones to verify that quot does not abort on first + # error. Note that quot deliberately ignores initial lines + # that don't start with a number, and that after encountering + # at least one line that does start with a number, quot would + # previously terminate on encountering one that doesn't (now + # it simply ignores them). This also tests that we don't + # require whitespace between the inode number and the comment. + echo "0zero" >>ninput + echo "invalid" >>ninput + echo "-1minusone" >>ninput # Create inodes owned by a large number of users to exercise # hash collisions and rehashing. The code uses an open hash # table that starts out with only 8 entries and doubles every @@ -50,6 +65,10 @@ quot_test() atf_check mount -ur /dev/$dev atf_check -o file:expect quot -fkN /dev/$dev atf_check -o file:expect quot -fkN $(realpath mnt) + # Test -n option + atf_check -o file:nexpect \ + -e inline:"quot: invalid inode 0\nquot: invalid inode -1\n" \ + quot -Nn /dev/$dev