[llvm] r183753 - Port r183666 to identify_magic.

Rafael Espindola rafael.espindola at gmail.com
Tue Jun 11 10:25:45 PDT 2013


Author: rafael
Date: Tue Jun 11 12:25:45 2013
New Revision: 183753

URL: http://llvm.org/viewvc/llvm-project?rev=183753&view=rev
Log:
Port r183666 to identify_magic.

It will be tested in the next commit which moves another user to identify_magic.

Original message:

Fix an out of bounds array access.

We were looking at Magic[5] without checking Length. Since this path would not
return unless Length >= 18 anyway, just move the >= 18 check up.

Modified:
    llvm/trunk/lib/Support/PathV2.cpp

Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=183753&r1=183752&r2=183753&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Tue Jun 11 12:25:45 2013
@@ -788,11 +788,12 @@ error_code has_magic(const Twine &path,
       break;
 
     case '\177':
-      if (Magic[1] == 'E' && Magic[2] == 'L' && Magic[3] == 'F') {
+      if (Magic.size() >= 18 && Magic[1] == 'E' && Magic[2] == 'L' &&
+          Magic[3] == 'F') {
         bool Data2MSB = Magic[5] == 2;
         unsigned high = Data2MSB ? 16 : 17;
         unsigned low  = Data2MSB ? 17 : 16;
-        if (Magic.size() >= 18 && Magic[high] == 0)
+        if (Magic[high] == 0)
           switch (Magic[low]) {
             default: break;
             case 1: return file_magic::elf_relocatable;





More information about the llvm-commits mailing list