Util-Linux Archive mirror
 help / color / mirror / Atom feed
From: Chris Hofstaedtler <zeha@debian.org>
To: util-linux@vger.kernel.org
Cc: наб <nabijaczleweli@nabijaczleweli.xyz>
Subject: [PATCH] script: abort if unused arguments are given
Date: Fri, 18 Nov 2022 13:23:37 +0000	[thread overview]
Message-ID: <20221118132337.616146-1-zeha@debian.org> (raw)

scripts uses either a free-standing "file" argument, or the value
passed as --log-out "file". Additional filenames are ignored.
They are also ignored if --log-in "file" is given, as it turns off
output logging by default (can still be overriden by adding --log-out).
Avoid surprises when passing multiple filenames by writing usage
message instead.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1016193
---
 term-utils/script.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 516a6cf93..c4b8e3337 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -889,9 +889,11 @@ int main(int argc, char **argv)
 
 	/* default if no --log-* specified */
 	if (!outfile && !infile) {
-		if (argc > 0)
+		if (argc > 0) {
 			outfile = argv[0];
-		else {
+			argc--;
+			argv++;
+		} else {
 			die_if_link(&ctl, DEFAULT_TYPESCRIPT_FILENAME);
 			outfile = DEFAULT_TYPESCRIPT_FILENAME;
 		}
@@ -900,6 +902,12 @@ int main(int argc, char **argv)
 		log_associate(&ctl, &ctl.out, outfile, SCRIPT_FMT_RAW);
 	}
 
+	if (argc > 0) {
+		/* only one filename is accepted. if --log-out was given,
+		 * freestanding filename is ignored */
+		usage();
+	}
+
 	if (timingfile) {
 		/* the old SCRIPT_FMT_TIMING_SIMPLE should be used when
 		 * recoding output only (just for backward compatibility),
-- 
2.38.1


             reply	other threads:[~2022-11-18 13:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 13:23 Chris Hofstaedtler [this message]
2022-11-21 10:09 ` [PATCH] script: abort if unused arguments are given Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221118132337.616146-1-zeha@debian.org \
    --to=zeha@debian.org \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).