Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

外部调用函数externalFunction返回值优化 #71

Open
cuanduo opened this issue Oct 7, 2023 · 0 comments
Open

外部调用函数externalFunction返回值优化 #71

cuanduo opened this issue Oct 7, 2023 · 0 comments

Comments

@cuanduo
Copy link

cuanduo commented Oct 7, 2023

在测试用例CWE78_OS_Command_Injection__char_connect_socket_system_01.out失败,经过分析发现,没有处理System调用返回值,导致在判断返回值时依据错误的rax值,导致部分路径不可达,从而未分析到漏洞路径。
sVar2 = strlen((char *)local_10);
*(undefined4 *)((longlong)local_10 + sVar2) = 0x2a2e2a;
iVar1 = system((char )local_10); 没有处理返回值,此时iVar1变量即rax是错误值
if (iVar1 != 0) {进入该分支,exit函数无返回导致分析中止,
printLine("command execution failed!");
/
WARNING: Subroutine does not return */
exit(1);
}
return;未进入该分支
建议当externalFunction没有自定义实现,且函数具有返回值时,将返回值设置为Top。
private Status invokeExternal(PcodeOp pcode, AbsEnv inOutEnv, AbsEnv tmpEnv, Function callee) {
String funcName = callee.getName();
ExternalFunctionBase externalFunction = FunctionModelManager.getExternalFunction(funcName);
if (externalFunction != null) {
Logging.debug("Invoke external function model: " + funcName);
externalFunction.invoke(pcode, inOutEnv, tmpEnv, context, callee);
} else {// change ret value
Parameter ret = callee.getReturn();
if (ret != null) {
Register retreg = ret.getRegister();
String rettype = ret.getDataType().getName();
if ((retreg != null) && (!rettype.equals("undefined"))){
ALoc retALoc = ALoc.getALoc(
Reg.getInstance(), retreg.getOffset(), GlobalState.arch.getDefaultPointerSize());
inOutEnv.set(retALoc, KSet.getTop(0), true);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant