summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Program.inc
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2017-06-20 20:51:51 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2017-06-20 20:51:51 +0000
commit8199dadab8237e25c39acdef7d8b1bc0835dff98 (patch)
treeb99a24691df6ab05a833f84b27ab06418aa257d7 /llvm/lib/Support/Unix/Program.inc
parent3dbef856d44b3d6336fe500a0dbf5ba2b3137d56 (diff)
downloadbcm5719-llvm-8199dadab8237e25c39acdef7d8b1bc0835dff98.tar.gz
bcm5719-llvm-8199dadab8237e25c39acdef7d8b1bc0835dff98.zip
Support: chunk writing on Linux
This is a workaround for large file writes. It has been witnessed that write(2) failing with EINVAL (22) due to a large value (>2G). Thanks to James Knight for the help with coming up with a sane test case. llvm-svn: 305846
Diffstat (limited to 'llvm/lib/Support/Unix/Program.inc')
-rw-r--r--llvm/lib/Support/Unix/Program.inc13
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index 2df0eaff47e..1704fa47994 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/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;
}
}
OpenPOWER on IntegriCloud