[llvm] r322536 - [FileCheck] - Fix possible buffer out of bounds access when parsing --check-prefix.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 00:09:25 PST 2018


Author: grimar
Date: Tue Jan 16 00:09:24 2018
New Revision: 322536

URL: http://llvm.org/viewvc/llvm-project?rev=322536&view=rev
Log:
[FileCheck] - Fix possible buffer out of bounds access when parsing --check-prefix.

FileCheck tool crashes when trying to parse --check-prefix argument if there is no any
data after it.

For example test like following would crash if there are no symbols and no EOL mark after `boom`:

# REQUIRES: x86
# RUN: <skipped few lines>
# RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=boom

Patch fixes the issue.

Differential revision: https://reviews.llvm.org/D42057

Added:
    llvm/trunk/test/FileCheck/check-empty2.txt
Modified:
    llvm/trunk/utils/FileCheck/FileCheck.cpp

Added: llvm/trunk/test/FileCheck/check-empty2.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/check-empty2.txt?rev=322536&view=auto
==============================================================================
--- llvm/trunk/test/FileCheck/check-empty2.txt (added)
+++ llvm/trunk/test/FileCheck/check-empty2.txt Tue Jan 16 00:09:24 2018
@@ -0,0 +1,4 @@
+; Check that tool does not crash when there is no any data
+; in file after -check-prefix=PREFIX option.
+
+; RUN: not FileCheck -input-file %s %s -check-prefix=A
\ No newline at end of file

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=322536&r1=322535&r2=322536&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Tue Jan 16 00:09:24 2018
@@ -718,6 +718,9 @@ static size_t CheckTypeSize(Check::Check
 }
 
 static Check::CheckType FindCheckType(StringRef Buffer, StringRef Prefix) {
+  if (Buffer.size() <= Prefix.size())
+    return Check::CheckNone;
+
   char NextChar = Buffer[Prefix.size()];
 
   // Verify that the : is present after the prefix.




More information about the llvm-commits mailing list