fix for compcov transform strings

This commit is contained in:
vanhauser-thc
2021-11-23 16:55:04 +01:00
parent 0e9b208949
commit d50da14f60

View File

@ -63,12 +63,14 @@ class CompareTransform : public PassInfoMixin<CompareTransform> {
public:
CompareTransform() {
#else
class CompareTransform : public ModulePass {
public:
static char ID;
CompareTransform() : ModulePass(ID) {
#endif
initInstrumentList();
@ -94,34 +96,46 @@ class CompareTransform : public ModulePass {
#if LLVM_MAJOR >= 7 /* use new pass manager */
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
return {
LLVM_PLUGIN_API_VERSION, "comparetransform", "v0.1",
return {LLVM_PLUGIN_API_VERSION, "comparetransform", "v0.1",
/* lambda to insert our pass into the pass pipeline. */
[](PassBuilder &PB) {
#if 1
using OptimizationLevel = typename PassBuilder::OptimizationLevel;
PB.registerOptimizerLastEPCallback(
[](ModulePassManager &MPM, OptimizationLevel OL) {
MPM.addPass(CompareTransform());
}
);
});
/* TODO LTO registration */
#else
using PipelineElement = typename PassBuilder::PipelineElement;
PB.registerPipelineParsingCallback(
[](StringRef Name, ModulePassManager &MPM, ArrayRef<PipelineElement>) {
PB.registerPipelineParsingCallback([](StringRef Name,
ModulePassManager &MPM,
ArrayRef<PipelineElement>) {
if (Name == "comparetransform") {
MPM.addPass(CompareTransform());
return true;
} else {
return false;
}
}
);
});
#endif
}};
}
};
}
#else
char CompareTransform::ID = 0;
#endif
@ -484,6 +498,9 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
}
// the following is in general OK, but strncmp is sometimes used in binary
// data structures and this can result in crashes :( so it is commented out
/*
// add null termination character implicit in c strings
if (!isMemcmp && TmpConstStr[TmpConstStr.length() - 1]) {
@ -491,6 +508,8 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
}
*/
// in the unusual case the const str has embedded null
// characters, the string comparison functions should terminate
// at the first null
@ -633,8 +652,10 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
#if LLVM_MAJOR >= 7 /* use new pass manager */
PreservedAnalyses CompareTransform::run(Module &M, ModuleAnalysisManager &MAM) {
#else
bool CompareTransform::runOnModule(Module &M) {
#endif
if ((isatty(2) && getenv("AFL_QUIET") == NULL) || getenv("AFL_DEBUG") != NULL)
@ -653,7 +674,9 @@ bool CompareTransform::runOnModule(Module &M) {
#if LLVM_MAJOR >= 7 /* use new pass manager */
/* if (modified) {
PA.abandon<XX_Manager>();
}*/
return PA;