Merge pull request #10297 from ethereum/linker-fix-spurious-errors-on-underscores

[linker] Avoid spurious errors on stray underscores in --link input
This commit is contained in:
chriseth 2020-11-24 12:02:15 +01:00 committed by GitHub
commit f9f9f6251d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,6 +55,7 @@
#include <libsolutil/CommonIO.h> #include <libsolutil/CommonIO.h>
#include <libsolutil/JSON.h> #include <libsolutil/JSON.h>
#include <algorithm>
#include <memory> #include <memory>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -1780,20 +1781,26 @@ bool CommandLineInterface::link()
{ {
while (it != end && *it != '_') ++it; while (it != end && *it != '_') ++it;
if (it == end) break; if (it == end) break;
if (end - it < placeholderSize) if (
end - it < placeholderSize ||
*(it + 1) != '_' ||
*(it + placeholderSize - 2) != '_' ||
*(it + placeholderSize - 1) != '_'
)
{ {
serr() << "Error in binary object file " << src.first << " at position " << (end - src.second.begin()) << endl; serr() << "Error in binary object file " << src.first << " at position " << (it - src.second.begin()) << endl;
serr() << '"' << string(it, it + min(placeholderSize, static_cast<int>(end - it))) << "\" is not a valid link reference." << endl;
return false; return false;
} }
string name(it, it + placeholderSize); string foundPlaceholder(it, it + placeholderSize);
if (librariesReplacements.count(name)) if (librariesReplacements.count(foundPlaceholder))
{ {
string hexStr(toHex(librariesReplacements.at(name).asBytes())); string hexStr(toHex(librariesReplacements.at(foundPlaceholder).asBytes()));
copy(hexStr.begin(), hexStr.end(), it); copy(hexStr.begin(), hexStr.end(), it);
} }
else else
serr() << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl; serr() << "Reference \"" << foundPlaceholder << "\" in file \"" << src.first << "\" still unresolved." << endl;
it += placeholderSize; it += placeholderSize;
} }
// Remove hints for resolved libraries. // Remove hints for resolved libraries.