From 107f7e3247a6ee767e92eddad60a3a79efa482ef Mon Sep 17 00:00:00 2001 From: Philipp Zieris <37868570+pzieris@users.noreply.github.com> Date: Thu, 3 Sep 2020 15:24:55 +0200 Subject: [PATCH] Fix handling of calls to memset --- include/Util/ExtAPI.h | 1 + lib/SVF-FE/PAGBuilder.cpp | 7 +++++++ lib/Util/ExtAPI.cpp | 10 ++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/Util/ExtAPI.h b/include/Util/ExtAPI.h index 3aba25e0a..c9d3b5500 100644 --- a/include/Util/ExtAPI.h +++ b/include/Util/ExtAPI.h @@ -60,6 +60,7 @@ class ExtAPI EFT_L_A1, EFT_L_A2, EFT_L_A8, + EFT_L_A0__A0R_A1, //stores arg1 into *arg0 and returns arg0 EFT_L_A0__A0R_A1R, //copies the data that arg1 points to into the location // arg0 points to; note that several fields may be // copied at once if both point to structs. diff --git a/lib/SVF-FE/PAGBuilder.cpp b/lib/SVF-FE/PAGBuilder.cpp index 640c71387..0d97069d9 100644 --- a/lib/SVF-FE/PAGBuilder.cpp +++ b/lib/SVF-FE/PAGBuilder.cpp @@ -949,6 +949,13 @@ void PAGBuilder::handleExtCall(CallSite cs, const SVFFunction *callee) break; break; } + case ExtAPI::EFT_L_A0__A0R_A1: + { + addComplexConsForExt(cs.getArgument(0), cs.getArgument(1)); + if(SVFUtil::isa(inst->getType())) + addCopyEdge(getValueNode(cs.getArgument(0)), getValueNode(inst)); + break; + } case ExtAPI::EFT_L_A0__A0R_A1R: { addComplexConsForExt(cs.getArgument(0), cs.getArgument(1)); diff --git a/lib/Util/ExtAPI.cpp b/lib/Util/ExtAPI.cpp index 1918a4e7a..ea3391d37 100644 --- a/lib/Util/ExtAPI.cpp +++ b/lib/Util/ExtAPI.cpp @@ -271,7 +271,6 @@ static const ei_pair ei_pairs[]= {"keypad", ExtAPI::EFT_NOOP}, {"lchown", ExtAPI::EFT_NOOP}, {"link", ExtAPI::EFT_NOOP}, - {"llvm.memset", ExtAPI::EFT_NOOP}, {"llvm.dbg", ExtAPI::EFT_NOOP}, {"llvm.stackrestore", ExtAPI::EFT_NOOP}, {"llvm.va_copy", ExtAPI::EFT_NOOP}, @@ -701,9 +700,6 @@ static const ei_pair ei_pairs[]= {"fgets", ExtAPI::EFT_L_A0}, {"jpeg_std_error", ExtAPI::EFT_L_A0}, {"memchr", ExtAPI::EFT_L_A0}, - //This will overwrite *arg0 with non-pointer data - - // assume that no valid pointer values are created. - {"memset", ExtAPI::EFT_L_A0}, //This may return a new ptr if the region was moved. {"mremap", ExtAPI::EFT_L_A0}, {"strchr", ExtAPI::EFT_L_A0}, @@ -728,10 +724,16 @@ static const ei_pair ei_pairs[]= {"inet_ntop", ExtAPI::EFT_L_A2}, {"XGetSubImage", ExtAPI::EFT_L_A8}, + {"memset", ExtAPI::EFT_L_A0__A0R_A1}, + {"llvm.memset", ExtAPI::EFT_L_A0__A0R_A1}, + {"llvm.memset.p0i8.i32", ExtAPI::EFT_L_A0__A0R_A1}, + {"llvm.memset.p0i8.i64", ExtAPI::EFT_L_A0__A0R_A1}, {"llvm.memcpy", ExtAPI::EFT_L_A0__A0R_A1R}, {"llvm.memcpy.p0i8.p0i8.i32", ExtAPI::EFT_L_A0__A0R_A1R}, {"llvm.memcpy.p0i8.p0i8.i64", ExtAPI::EFT_L_A0__A0R_A1R}, {"llvm.memmove", ExtAPI::EFT_L_A0__A0R_A1R}, + {"llvm.memmove.p0i8.p0i8.i32", ExtAPI::EFT_L_A0__A0R_A1R}, + {"llvm.memmove.p0i8.p0i8.i64", ExtAPI::EFT_L_A0__A0R_A1R}, {"memccpy", ExtAPI::EFT_L_A0__A0R_A1R}, {"memcpy", ExtAPI::EFT_L_A0__A0R_A1R}, {"memmove", ExtAPI::EFT_L_A0__A0R_A1R},