diff options
author | Yuri Pankov <yuripv@FreeBSD.org> | 2023-04-17 19:14:33 +0000 |
---|---|---|
committer | Yuri Pankov <yuripv@FreeBSD.org> | 2023-04-17 20:20:03 +0000 |
commit | 21ef48af5c0f4ed85a5f42855b5a8d58b5431103 (patch) | |
tree | 44cfb1a7645c45bf0a73b96308738132282fd5e3 | |
parent | b03311cadd3a6f931e176f97b97bd72be3ef96d4 (diff) | |
download | src-21ef48af5c0f4ed85a5f42855b5a8d58b5431103.tar.gz src-21ef48af5c0f4ed85a5f42855b5a8d58b5431103.zip |
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
-rw-r--r-- | usr.bin/xargs/xargs.c | 7 |
1 files 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) { |