@@ -944,18 +944,20 @@ ImportFile::ImportFile(COFFLinkerContext &ctx, MemoryBufferRef m)
944
944
: InputFile(ctx, ImportKind, m), live(!ctx.config.doGC), thunkLive(live) {}
945
945
946
946
void ImportFile::parse () {
947
- const char *buf = mb. getBufferStart ();
948
- const auto *hdr = reinterpret_cast <const coff_import_header *>(buf );
947
+ const auto *hdr =
948
+ reinterpret_cast <const coff_import_header *>(mb. getBufferStart () );
949
949
950
950
// Check if the total size is valid.
951
- if (mb.getBufferSize () != sizeof (*hdr) + hdr->SizeOfData )
951
+ if (mb.getBufferSize () < sizeof (*hdr) ||
952
+ mb.getBufferSize () != sizeof (*hdr) + hdr->SizeOfData )
952
953
fatal (" broken import library" );
953
954
954
955
// Read names and create an __imp_ symbol.
955
- StringRef name = saver ().save (StringRef (buf + sizeof (*hdr)));
956
+ StringRef buf = mb.getBuffer ().substr (sizeof (*hdr));
957
+ StringRef name = saver ().save (buf.split (' \0 ' ).first );
956
958
StringRef impName = saver ().save (" __imp_" + name);
957
- const char *nameStart = buf + sizeof (coff_import_header) + name.size () + 1 ;
958
- dllName = std::string ( StringRef (nameStart)) ;
959
+ buf = buf. substr ( name.size () + 1 ) ;
960
+ dllName = buf. split ( ' \0 ' ). first ;
959
961
StringRef extName;
960
962
switch (hdr->getNameType ()) {
961
963
case IMPORT_ORDINAL:
@@ -971,6 +973,9 @@ void ImportFile::parse() {
971
973
extName = ltrim1 (name, " ?@_" );
972
974
extName = extName.substr (0 , extName.find (' @' ));
973
975
break ;
976
+ case IMPORT_NAME_EXPORTAS:
977
+ extName = buf.substr (dllName.size () + 1 ).split (' \0 ' ).first ;
978
+ break ;
974
979
}
975
980
976
981
this ->hdr = hdr;
0 commit comments