Fix global overflow in types::lookupTypeForTypeSpecifier.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 28 Feb 2013 07:53:32 +0000 (07:53 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 28 Feb 2013 07:53:32 +0000 (07:53 +0000)
memcpy() is allowed to read entire contents of both memory areas.

Found with AddressSanitizer.

llvm-svn: 176237

clang/lib/Driver/Types.cpp

index cab6dcc..88574fc 100644 (file)
@@ -168,12 +168,10 @@ types::ID types::lookupTypeForExtension(const char *Ext) {
 }
 
 types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
-  unsigned N = strlen(Name);
-
   for (unsigned i=0; i<numTypes; ++i) {
     types::ID Id = (types::ID) (i + 1);
     if (canTypeBeUserSpecified(Id) &&
-        memcmp(Name, getInfo(Id).Name, N + 1) == 0)
+        strcmp(Name, getInfo(Id).Name) == 0)
       return Id;
   }