diff options
| author | Jonas Hahnfeld <hahnjo@hahnjo.de> | 2019-03-13 10:37:56 +0000 |
|---|---|---|
| committer | Jonas Hahnfeld <hahnjo@hahnjo.de> | 2019-03-13 10:37:56 +0000 |
| commit | e59746f8f823b833e902d79468d9779431744ddd (patch) | |
| tree | 36259097cd66aab10474dbdd9de19e5b60f5752b | |
| parent | 18f95e6a6f1abf486f84ced59edebdc2227a9de2 (diff) | |
| download | bcm5719-llvm-e59746f8f823b833e902d79468d9779431744ddd.tar.gz bcm5719-llvm-e59746f8f823b833e902d79468d9779431744ddd.zip | |
[Support] Treat truncation of fullpath as error
If the concatenation of arguments dir and bin has at least PATH_MAX
characters the call to snprintf will truncate. The result will usually
not exist, but if it does it's actually incorrect to return that the
path exists.
(Motivated by GCC compiler warning about format truncation.)
Differential Revision: https://reviews.llvm.org/D58835
llvm-svn: 356036
| -rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 5eba86d2077..57385baaf34 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -107,7 +107,11 @@ test_dir(char ret[PATH_MAX], const char *dir, const char *bin) struct stat sb; char fullpath[PATH_MAX]; - snprintf(fullpath, PATH_MAX, "%s/%s", dir, bin); + int chars = snprintf(fullpath, PATH_MAX, "%s/%s", dir, bin); + // We cannot write PATH_MAX characters because the string will be terminated + // with a null character. Fail if truncation happened. + if (chars >= PATH_MAX) + return 1; if (!realpath(fullpath, ret)) return 1; if (stat(fullpath, &sb) != 0) |

