Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Apr 2023 20:22:00 GMT
From:      Yuri Pankov <yuripv@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 21ef48af5c0f - main - xargs: improve foundeof check for -E
Message-ID:  <202304172022.33HKM0vg030578@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by yuripv:

URL: https://cgit.FreeBSD.org/src/commit/?id=21ef48af5c0f4ed85a5f42855b5a8d58b5431103

commit 21ef48af5c0f4ed85a5f42855b5a8d58b5431103
Author:     Yuri Pankov <yuripv@FreeBSD.org>
AuthorDate: 2023-04-17 19:14:33 +0000
Commit:     Yuri Pankov <yuripv@FreeBSD.org>
CommitDate: 2023-04-17 20:20:03 +0000

    xargs: improve foundeof check for -E
    
    4aeb63826e0f got it almost correct (we can't use strcmp() here as
    current argument isn't guaranteed to be NUL-terminated), but we also
    need to check that current argument length is equal to that of eofstr.
    
    PR:             270867
    Reviewed by:    bapt
    Differential Revision:  https://reviews.freebsd.org/D39583
---
 usr.bin/xargs/xargs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index 21455e7be26e..cadb0c76cc2f 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -91,6 +91,7 @@ static char echo[] = _PATH_ECHO;
 static char **av, **bxp, **ep, **endxp, **xp;
 static char *argp, *bbp, *ebp, *inpline, *p, *replstr;
 static const char *eofstr;
+static long eoflen;
 static int count, insingle, indouble, oflag, pflag, tflag, Rflag, rval, zflag;
 static int cnt, Iflag, jfound, Lflag, Sflag, wasquoted, xflag;
 static int curprocs, maxprocs;
@@ -129,6 +130,7 @@ main(int argc, char *argv[])
 	inpline = replstr = NULL;
 	ep = environ;
 	eofstr = "";
+	eoflen = 0;
 	Jflag = nflag = 0;
 
 	(void)setlocale(LC_ALL, "");
@@ -159,6 +161,7 @@ main(int argc, char *argv[])
 		switch (ch) {
 		case 'E':
 			eofstr = optarg;
+			eoflen = strlen(eofstr);
 			break;
 		case 'I':
 			Jflag = 0;
@@ -348,8 +351,8 @@ arg1:		if (insingle || indouble) {
 			xexit(*av, 1);
 		}
 arg2:
-		foundeof = *eofstr != '\0' &&
-		    strncmp(argp, eofstr, p - argp) == 0;
+		foundeof = eoflen != 0 && p - argp == eoflen &&
+		    strncmp(argp, eofstr, eoflen) == 0;
 
 		/* Do not make empty args unless they are quoted */
 		if ((argp != p || wasquoted) && !foundeof) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304172022.33HKM0vg030578>