summaryrefslogtreecommitdiff
path: root/lib/Support/Unix/Program.inc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-26 20:32:52 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-26 20:32:52 +0000
commit08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (patch)
tree80108f0f128657f8623f8f66ad9735b4d88e7b47 /lib/Support/Unix/Program.inc
parent7c7aba6e5fef47a01a136be655b0a92cfd7090f6 (diff)
Notes
Diffstat (limited to 'lib/Support/Unix/Program.inc')
-rw-r--r--lib/Support/Unix/Program.inc13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc
index 2df0eaff47e52..1704fa4799428 100644
--- a/lib/Support/Unix/Program.inc
+++ b/lib/Support/Unix/Program.inc
@@ -449,11 +449,22 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<co
size_t ArgLength = Program.size() + 1;
for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
I != E; ++I) {
- ArgLength += strlen(*I) + 1;
+ size_t length = strlen(*I);
+
+ // Ensure that we do not exceed the MAX_ARG_STRLEN constant on Linux, which
+ // does not have a constant unlike what the man pages would have you
+ // believe. Since this limit is pretty high, perform the check
+ // unconditionally rather than trying to be aggressive and limiting it to
+ // Linux only.
+ if (length >= (32 * 4096))
+ return false;
+
+ ArgLength += length + 1;
if (ArgLength > size_t(HalfArgMax)) {
return false;
}
}
+
return true;
}
}