aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2004-10-18 15:40:47 +0000
committerColin Percival <cperciva@FreeBSD.org>2004-10-18 15:40:47 +0000
commit5578bd8c991bd987dbf63ea87d5588e50fb410c3 (patch)
tree12862be879f6a897ea7e3cfc37baaaa5412ed197 /usr.bin/xargs
parent585d0283b032cd7650e600e8e3c9c9780a3f61e5 (diff)
downloadsrc-5578bd8c991bd987dbf63ea87d5588e50fb410c3.tar.gz
src-5578bd8c991bd987dbf63ea87d5588e50fb410c3.zip
Modify behaviour of `xargs -I` in order to:
1. Conform to IEEE Std 1003.1-2004, which state that "Constructed arguments cannot grow larger than 255 bytes", and 2. Avoid a buffer overflow. Unfortunately the standard doesn't indicate how xargs is supposed to handle arguments which (with the appropriate substitutions) would grow larger than 255 bytes; this solution handles those by making as many substitutions as possible without overflowing the buffer. OpenBSD's xargs resolves this in a different direction, by making all the substitutions and then silently truncating the resulting string. Since this change may break existing scripts which rely upon the buffer overflow (255 bytes isn't really all that long...) it will not be MFCed.
Notes
Notes: svn path=/head/; revision=136664
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/strnsubst.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c
index fc00ea0db321..82868ffc3d82 100644
--- a/usr.bin/xargs/strnsubst.c
+++ b/usr.bin/xargs/strnsubst.c
@@ -52,8 +52,8 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize)
this = strstr(s1, match);
if (this == NULL)
break;
- if ((strlen(s2) + ((uintptr_t)this - (uintptr_t)s1) +
- (strlen(replstr) - 1)) > maxsize && *replstr != '\0') {
+ if ((strlen(s2) + strlen(s1) + strlen(replstr) -
+ strlen(match) + 1) > maxsize) {
strlcat(s2, s1, maxsize);
goto done;
}