mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-12 10:08:07 +00:00
fix zero terminated string issue
In C "strings" are zero terminated. Functions like strcmp/strncmp/memcmp/... work on them. We have to be careful to not ignore the last byte.
This commit is contained in:
@ -184,6 +184,7 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const
|
|||||||
|
|
||||||
Value *Str1P = callInst->getArgOperand(0), *Str2P = callInst->getArgOperand(1);
|
Value *Str1P = callInst->getArgOperand(0), *Str2P = callInst->getArgOperand(1);
|
||||||
StringRef Str1, Str2, ConstStr;
|
StringRef Str1, Str2, ConstStr;
|
||||||
|
std::string TmpConstStr;
|
||||||
Value *VarStr;
|
Value *VarStr;
|
||||||
bool HasStr1 = getConstantStringInfo(Str1P, Str1);
|
bool HasStr1 = getConstantStringInfo(Str1P, Str1);
|
||||||
getConstantStringInfo(Str2P, Str2);
|
getConstantStringInfo(Str2P, Str2);
|
||||||
@ -202,21 +203,20 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HasStr1) {
|
if (HasStr1) {
|
||||||
ConstStr = Str1;
|
TmpConstStr = Str1.str();
|
||||||
VarStr = Str2P;
|
VarStr = Str2P;
|
||||||
constLen = isMemcmp ? sizedLen : GetStringLength(Str1P);
|
constLen = isMemcmp ? sizedLen : GetStringLength(Str1P);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ConstStr = Str2;
|
TmpConstStr = Str2.str();
|
||||||
VarStr = Str1P;
|
VarStr = Str1P;
|
||||||
constLen = isMemcmp ? sizedLen : GetStringLength(Str2P);
|
constLen = isMemcmp ? sizedLen : GetStringLength(Str2P);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bugfix thanks to pbst */
|
/* properly handle zero terminated C strings by adding the terminating 0 to
|
||||||
/* ignore terminating '\0' in string for strcmp */
|
* the StringRef (in comparison to std::string a StringRef has built-in
|
||||||
if (!isSizedcmp && constLen > 0) {
|
* runtime bounds checking, which makes debugging easier) */
|
||||||
constLen--;
|
TmpConstStr.append("\0", 1); ConstStr = StringRef(TmpConstStr);
|
||||||
}
|
|
||||||
|
|
||||||
if (isSizedcmp && constLen > sizedLen) {
|
if (isSizedcmp && constLen > sizedLen) {
|
||||||
constLen = sizedLen;
|
constLen = sizedLen;
|
||||||
|
Reference in New Issue
Block a user