Skip to content

Commit

Permalink
non ub exploit mode: fix false positive with fn calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Aug 25, 2023
1 parent aa78abe commit ce35c2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,8 +2067,16 @@ unique_ptr<Instr> InsertValue::dup(Function &f, const string &suffix) const {
return ret;
}


DEFINE_AS_RETZERO(FnCall, getMaxGEPOffset);

FnCall::FnCall(Type &type, string &&name, string &&fnName, FnAttrs &&attrs)
: MemInstr(type, std::move(name)), fnName(std::move(fnName)),
attrs(std::move(attrs)) {
if (config::disallow_ub_exploitation)
this->attrs.set(FnAttrs::NoUndef);
}

pair<uint64_t, uint64_t> FnCall::getMaxAllocSize() const {
if (!hasAttribute(FnAttrs::AllocSize))
return { 0, 1 };
Expand Down
4 changes: 1 addition & 3 deletions ir/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,9 +1024,7 @@ class FnCall : public MemInstr {

public:
FnCall(Type &type, std::string &&name, std::string &&fnName,
FnAttrs &&attrs = FnAttrs::None)
: MemInstr(type, std::move(name)), fnName(std::move(fnName)),
attrs(std::move(attrs)) {}
FnAttrs &&attrs = FnAttrs::None);
void addArg(Value &arg, ParamAttrs &&attrs);
const auto& getFnName() const { return fnName; }
const auto& getArgs() const { return args; }
Expand Down
15 changes: 15 additions & 0 deletions tests/alive-tv/non-ub-exploitation/fncall.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; TEST-ARGS: -disallow-ub-exploitation

declare ptr @fn() null_pointer_is_valid

define i32 @src() null_pointer_is_valid {
%call1 = call ptr @fn()
load i32, ptr %call1, align 1
ret i32 0
}

define i32 @tgt() null_pointer_is_valid {
%call1 = call ptr @fn()
load i32, ptr %call1, align 1
ret i32 0
}

0 comments on commit ce35c2b

Please sign in to comment.