[PATCH] D58835: [Support] Treat truncation of fullpath as error

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 03:38:32 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL356036: [Support] Treat truncation of fullpath as error (authored by Hahnfeld, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58835?vs=188938&id=190389#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58835/new/

https://reviews.llvm.org/D58835

Files:
  llvm/trunk/lib/Support/Unix/Path.inc


Index: llvm/trunk/lib/Support/Unix/Path.inc
===================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc
+++ llvm/trunk/lib/Support/Unix/Path.inc
@@ -107,7 +107,11 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58835.190389.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/4be897dc/attachment.bin>


More information about the llvm-commits mailing list