Static Value-Flow Analysis
Loading...
Searching...
No Matches
AEDetector.cpp
Go to the documentation of this file.
1//===- AEDetector.cpp -- Vulnerability Detectors---------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23
24//
25// Created on: May 1, 2025
26// Author: Xiao Cheng, Jiawei Wang, Mingxiu Wang
27//
28
30#include <AE/Svfexe/AbsExtAPI.h>
33#include <algorithm>
34
35using namespace SVF;
47{
50 {
51 // Handle non-call nodes by analyzing GEP instructions
52 for (const SVFStmt* stmt : node->getSVFStmts())
53 {
54 if (const GepStmt* gep = SVFUtil::dyn_cast<GepStmt>(stmt))
55 {
56 SVFIR* svfir = PAG::getPAG();
57
58 // Update the GEP object offset from its base
59 const AbstractValue& lhsVal = ae.getAbsValue(gep->getLHSVar(), node);
60 const AbstractValue& rhsVal = ae.getAbsValue(gep->getRHSVar(), node);
61 updateGepObjOffsetFromBase(node, lhsVal.getAddrs(), rhsVal.getAddrs(),
62 ae.getGepByteOffset(gep));
63
64 const AddressValue& objAddrs = rhsVal.getAddrs();
65 bool hasUnknownSizeTarget = false;
66 for (const auto& addr : objAddrs)
67 {
68 // Null/black-hole objects have neither an allocation size nor
69 // a defining ICFG node that can be inspected below.
70 const NodeID objId = ae.getAbsState(node).getIDFromAddr(addr);
71 if (svfir->isNullOrBlkObj(objId))
72 {
73 hasUnknownSizeTarget = true;
74 continue;
75 }
76 u32_t size = 0;
77 u32_t lower = 0;
78 // like `int arr[10]` which has constant size before runtime
79 if (svfir->getBaseObject(objId)->isConstantByteSize())
80 {
81 size = svfir->getBaseObject(objId)->getByteSizeOfObj();
82 lower = size;
83 }
84 else
85 {
86 // like `int len = ***; int arr[len]`, whose size can only be known in runtime
87 const ICFGNode* addrNode = svfir->getBaseObject(objId)->getICFGNode();
88 if (!addrNode)
89 {
90 hasUnknownSizeTarget = true;
91 continue;
92 }
93 for (const SVFStmt* stmt2 : addrNode->getSVFStmts())
94 {
95 if (const AddrStmt* addrStmt = SVFUtil::dyn_cast<AddrStmt>(stmt2))
96 {
97 const auto bounds = ae.getAllocaInstByteSize(addrStmt);
98 size = bounds.upperBound;
99 lower = bounds.lowerBound;
100 }
101 }
102 }
103
104 // Calculate access offset and check for potential overflow
105 IntervalValue accessOffset = getAccessOffset(objId, gep);
106 if (accessOffset.ub().getIntNumeral() >= size)
107 {
108 AEException bug(stmt->toString());
109 addBugToReporter(bug, stmt->getICFGNode(),
110 {IntervalValue(lower, size), accessOffset});
111 }
112 }
113 // Some target has no known allocation size, so report one
114 // alarm with an unbounded size and the GEP's own byte offset.
115 if (hasUnknownSizeTarget)
116 addBugToReporter(AEException(stmt->toString()), node,
117 {
118 IntervalValue(0, IntervalValue::plus_infinity()),
119 ae.getGepByteOffset(gep)
120 });
121 }
122 }
123 }
124 else
125 {
126 // Handle call nodes by checking for external API calls
127 const CallICFGNode* callNode = SVFUtil::cast<CallICFGNode>(node);
128 if (SVFUtil::isExtCall(callNode->getCalledFunction()))
129 {
130 detectExtAPI(callNode);
131 }
132 }
133}
134
135
144{
145 // get function name
146 std::string funcName = callNode->getCalledFunction()->getName();
148 if (funcName == "SAFE_BUFACCESS")
149 {
150 ae.getUtils()->checkpoints.erase(callNode);
151 if (callNode->arg_size() < 2)
152 return;
153 IntervalValue val = ae.getAbsValue(callNode->getArgument(1), callNode).getInterval();
154 if (val.isBottom())
155 {
156 val = IntervalValue(0);
157 assert(false && "SAFE_BUFACCESS size is bottom");
158 }
159 const ValVar* arg0Val = callNode->getArgument(0);
160 bool isSafe = canSafelyAccessMemory(arg0Val, val, callNode);
161 if (isSafe)
162 {
163 SVFUtil::outs() << SVFUtil::sucMsg("success: expected safe buffer access at SAFE_BUFACCESS")
164 << " — " << callNode->toString() << "\n";
165 return;
166 }
167 else
168 {
169 SVFUtil::outs() << SVFUtil::errMsg("failure: unexpected buffer overflow at SAFE_BUFACCESS")
170 << " — Position: " << callNode->getSourceLoc() << "\n";
171 assert(false);
172 }
173 }
174 else if (funcName == "UNSAFE_BUFACCESS")
175 {
176 ae.getUtils()->checkpoints.erase(callNode);
177 if (callNode->arg_size() < 2) return;
178 IntervalValue val = ae.getAbsValue(callNode->getArgument(1), callNode).getInterval();
179 if (val.isBottom())
180 {
181 assert(false && "UNSAFE_BUFACCESS size is bottom");
182 }
183 const ValVar* arg0Val = callNode->getArgument(0);
184 bool isSafe = canSafelyAccessMemory(arg0Val, val, callNode);
185 if (!isSafe)
186 {
187 SVFUtil::outs() << SVFUtil::sucMsg("success: expected buffer overflow at UNSAFE_BUFACCESS")
188 << " — " << callNode->toString() << "\n";
189 return;
190 }
191 else
192 {
193 SVFUtil::outs() << SVFUtil::errMsg("failure: buffer overflow expected at UNSAFE_BUFACCESS, but none detected")
194 << " — Position: " << callNode->getSourceLoc() << "\n";
195 assert(false);
196 }
197 }
198}
199
207{
208 extAPIBufOverflowCheckRules["llvm_memcpy_p0i8_p0i8_i64"] = {{0, 2}, {1, 2}};
209 extAPIBufOverflowCheckRules["llvm_memcpy_p0_p0_i64"] = {{0, 2}, {1, 2}};
210 extAPIBufOverflowCheckRules["llvm_memcpy_p0i8_p0i8_i32"] = {{0, 2}, {1, 2}};
211 extAPIBufOverflowCheckRules["llvm_memcpy"] = {{0, 2}, {1, 2}};
212 extAPIBufOverflowCheckRules["llvm_memmove"] = {{0, 2}, {1, 2}};
213 extAPIBufOverflowCheckRules["llvm_memmove_p0i8_p0i8_i64"] = {{0, 2}, {1, 2}};
214 extAPIBufOverflowCheckRules["llvm_memmove_p0_p0_i64"] = {{0, 2}, {1, 2}};
215 extAPIBufOverflowCheckRules["llvm_memmove_p0i8_p0i8_i32"] = {{0, 2}, {1, 2}};
216 extAPIBufOverflowCheckRules["__memcpy_chk"] = {{0, 2}, {1, 2}};
217 extAPIBufOverflowCheckRules["memmove"] = {{0, 2}, {1, 2}};
218 extAPIBufOverflowCheckRules["bcopy"] = {{0, 2}, {1, 2}};
219 extAPIBufOverflowCheckRules["memccpy"] = {{0, 3}, {1, 3}};
220 extAPIBufOverflowCheckRules["__memmove_chk"] = {{0, 2}, {1, 2}};
221 extAPIBufOverflowCheckRules["llvm_memset"] = {{0, 2}};
222 extAPIBufOverflowCheckRules["llvm_memset_p0i8_i32"] = {{0, 2}};
223 extAPIBufOverflowCheckRules["llvm_memset_p0i8_i64"] = {{0, 2}};
224 extAPIBufOverflowCheckRules["llvm_memset_p0_i64"] = {{0, 2}};
225 extAPIBufOverflowCheckRules["__memset_chk"] = {{0, 2}};
226 extAPIBufOverflowCheckRules["wmemset"] = {{0, 2}};
227 extAPIBufOverflowCheckRules["strncpy"] = {{0, 2}, {1, 2}};
228 extAPIBufOverflowCheckRules["iconv"] = {{1, 2}, {3, 4}};
229}
230
240{
241 assert(call->getCalledFunction() && "FunObjVar* is nullptr");
243
245
246 // Determine the type of external memory API
247 for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction()))
248 {
249 if (annotation.find("MEMCPY") != std::string::npos)
250 extType = AbsExtAPI::MEMCPY;
251 if (annotation.find("MEMSET") != std::string::npos)
252 extType = AbsExtAPI::MEMSET;
253 if (annotation.find("STRCPY") != std::string::npos)
254 extType = AbsExtAPI::STRCPY;
255 if (annotation.find("STRCAT") != std::string::npos)
256 extType = AbsExtAPI::STRCAT;
257 }
258
259 // Apply buffer overflow checks based on the determined API type
261 if (extType == AbsExtAPI::MEMCPY)
262 {
263 if (extAPIBufOverflowCheckRules.count(call->getCalledFunction()->getName()) == 0)
264 {
265 SVFUtil::errs() << "Warning: " << call->getCalledFunction()->getName() << " is not in the rules, please implement it\n";
266 return;
267 }
268 std::vector<std::pair<u32_t, u32_t>> args =
270 for (auto arg : args)
271 {
272 IntervalValue offset = ae.getAbsValue(call->getArgument(arg.second), call).getInterval() - IntervalValue(1);
273 const ValVar* argVar = call->getArgument(arg.first);
274 if (!canSafelyAccessMemory(argVar, offset, call, &info))
275 {
276 AEException bug(call->toString());
277 addBugToReporter(bug, call, info);
278 }
279 }
280 }
281 else if (extType == AbsExtAPI::MEMSET)
282 {
283 if (extAPIBufOverflowCheckRules.count(call->getCalledFunction()->getName()) == 0)
284 {
285 SVFUtil::errs() << "Warning: " << call->getCalledFunction()->getName() << " is not in the rules, please implement it\n";
286 return;
287 }
288 std::vector<std::pair<u32_t, u32_t>> args =
290 for (auto arg : args)
291 {
292 IntervalValue offset = ae.getAbsValue(call->getArgument(arg.second), call).getInterval() - IntervalValue(1);
293 const ValVar* argVar = call->getArgument(arg.first);
294 if (!canSafelyAccessMemory(argVar, offset, call, &info))
295 {
296 AEException bug(call->toString());
297 addBugToReporter(bug, call, info);
298 }
299 }
300 }
301 else if (extType == AbsExtAPI::STRCPY)
302 {
303 if (!detectStrcpy(call, info))
304 {
305 AEException bug(call->toString());
306 addBugToReporter(bug, call, info);
307 }
308 }
309 else if (extType == AbsExtAPI::STRCAT)
310 {
311 if (!detectStrcat(call, info))
312 {
313 AEException bug(call->toString());
314 addBugToReporter(bug, call, info);
315 }
316 }
317 else
318 {
319 // Handle other cases
320 }
321}
322
334{
335 SVFIR* svfir = PAG::getPAG();
337 auto obj = svfir->getSVFVar(objId);
338
340 {
341 return ae.getGepByteOffset(gep);
342 }
343 else if (SVFUtil::isa<GepObjVar>(obj))
344 {
345 return getGepObjOffsetFromBase(SVFUtil::cast<GepObjVar>(obj)) + ae.getGepByteOffset(gep);
346 }
347 else
348 {
349 assert(SVFUtil::isa<DummyObjVar>(obj) && "Unknown object type");
350 return IntervalValue::top();
351 }
352}
353
365{
366 SVFIR* svfir = PAG::getPAG();
368 const AbstractState& as = ae.getAbsState(node);
369
370 for (const auto& objAddr : objAddrs)
371 {
372 NodeID objId = as.getIDFromAddr(objAddr);
373 if (svfir->isNullOrBlkObj(objId)) continue;
374 auto obj = svfir->getSVFVar(objId);
375
377 {
378 // if the object is a BaseObjVar, add the offset directly
379 // like llvm bc `arr = alloc i8 12; p = gep arr, 4`
380 // we write key value pair {gep, 4}
381 for (const auto& gepAddr : gepAddrs)
382 {
383 NodeID gepObj = as.getIDFromAddr(gepAddr);
384 if (const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(svfir->getSVFVar(gepObj)))
385 {
387 }
388 else if (SVFUtil::isa<BaseObjVar>(svfir->getSVFVar(gepObj)) &&
389 svfir->getBaseObject(gepObj) == svfir->getBaseObject(objId))
390 {
391 // First-field and field-insensitive GEPs retain the base Obj.
392 }
393 else
394 {
395 assert(svfir->isNullOrBlkObj(gepObj) &&
396 "GEP object is neither a GepObjVar nor an address without a backing object");
397 }
398 }
399 }
400 else if (SVFUtil::isa<GepObjVar>(obj))
401 {
402 // if the object is a GepObjVar, add the offset from the base object
403 // like llvm bc `arr = alloc i8 12; p = gep arr, 4; q = gep p, 6`
404 // we retreive {p, 4} and write {q, 4+6}
405 const GepObjVar* objVar = SVFUtil::cast<GepObjVar>(obj);
406 for (const auto& gepAddr : gepAddrs)
407 {
408 NodeID gepObj = as.getIDFromAddr(gepAddr);
409 if (const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(svfir->getSVFVar(gepObj)))
410 {
411 if (hasGepObjOffsetFromBase(objVar))
412 {
413 IntervalValue objOffsetFromBase =
415 if (!hasGepObjOffsetFromBase(gepObjVar))
417 gepObjVar, objOffsetFromBase + offset);
418 }
419 else
420 {
421 assert(false &&
422 "GEP RHS object has no offset from base");
423 }
424 }
425 else if (SVFUtil::isa<BaseObjVar>(svfir->getSVFVar(gepObj)) &&
426 svfir->getBaseObject(gepObj) == svfir->getBaseObject(objId))
427 {
428 // A collapsed field has no distinct GepObjVar offset to record.
429 }
430 else
431 {
432 assert(svfir->isNullOrBlkObj(gepObj) &&
433 "GEP object is neither a GepObjVar nor an address without a backing object");
434 }
435 }
436 }
437 }
438}
439
451{
452 const ValVar* arg0Val = call->getArgument(0);
453 const ValVar* arg1Val = call->getArgument(1);
455 IntervalValue strLen = ae.getUtils()->getStrlen(arg1Val, call);
456 return canSafelyAccessMemory(arg0Val, ae.getUtils()->getStringLastByte(call, strLen), call, &info);
457}
458
460{
462 const std::vector<std::string> strcatGroup = {"__strcat_chk", "strcat", "__wcscat_chk", "wcscat"};
463 const std::vector<std::string> strncatGroup = {"__strncat_chk", "strncat", "__wcsncat_chk", "wcsncat"};
464
465 // Detectors see the state after the call, where dst already holds the
466 // concatenation, so strlen(dst) is the index of the new terminator.
467 // If the append overflowed, no terminator is inside dst and the length
468 // stays unbounded above, which keeps the reported access sound.
469 if (std::find(strcatGroup.begin(), strcatGroup.end(), call->getCalledFunction()->getName()) != strcatGroup.end() ||
470 std::find(strncatGroup.begin(), strncatGroup.end(), call->getCalledFunction()->getName()) != strncatGroup.end())
471 {
472 const ValVar* arg0Val = call->getArgument(0);
473 IntervalValue totalLen = ae.getUtils()->getStrlen(arg0Val, call);
474 return canSafelyAccessMemory(arg0Val, ae.getUtils()->getStringLastByte(call, totalLen), call, &info);
475 }
476 else
477 {
478 assert(false && "Unknown strcat function, please add it to strcatGroup or strncatGroup");
479 abort();
480 }
481}
482
495 const ICFGNode* node, BufferOverflowInfo* info)
496{
497 if (info) *info = {};
498 SVFIR* svfir = PAG::getPAG();
500
501 AbstractValue ptrVal = ae.getAbsValue(value, node);
502 if (!ptrVal.isAddr())
503 {
505 ae.updateAbsValue(value, ptrVal, node);
506 }
507
508 const AddressValue& addresses = ptrVal.getAddrs();
509 if (std::any_of(addresses.begin(), addresses.end(), [&](u32_t addr)
510{
511 return svfir->isNullOrBlkObj(ae.getAbsState(node).getIDFromAddr(addr));
512 }))
513 return false;
514
515 for (const auto& addr : addresses)
516 {
517 NodeID objId = ae.getAbsState(node).getIDFromAddr(addr);
518 u32_t size = 0;
519 u32_t lower = 0;
520 // if the object is a constant size object, get the size directly
521 if (svfir->getBaseObject(objId)->isConstantByteSize())
522 {
523 size = svfir->getBaseObject(objId)->getByteSizeOfObj();
524 lower = size;
525 }
526 else
527 {
528 // if the object is not a constant size object, get the size from the addrStmt
529 const ICFGNode* addrNode = svfir->getBaseObject(objId)->getICFGNode();
530 if (!addrNode)
531 return false;
532 for (const SVFStmt* stmt2 : addrNode->getSVFStmts())
533 {
534 if (const AddrStmt* addrStmt = SVFUtil::dyn_cast<AddrStmt>(stmt2))
535 {
536 const auto bounds = ae.getAllocaInstByteSize(addrStmt);
537 size = bounds.upperBound;
538 lower = bounds.lowerBound;
539 }
540 }
541 }
542
544 // if the object is a GepObjVar, get the offset from the base object
545 if (SVFUtil::isa<GepObjVar>(svfir->getSVFVar(objId)))
546 {
548 }
549 else if (SVFUtil::isa<BaseObjVar>(svfir->getSVFVar(objId)))
550 {
551 // if the object is a BaseObjVar, get the offset directly
552 offset = len;
553 }
554
555 // if the offset is greater than the size, return false
556 if (offset.ub().getIntNumeral() >= size)
557 {
558 if (info) *info = {IntervalValue(lower, size), offset};
559 return false;
560 }
561 }
562 return true;
563}
564
566{
568 {
569 // external API like memset(*dst, elem, sz)
570 // we check if it's external api and check the corrisponding index
571 const CallICFGNode* callNode = SVFUtil::cast<CallICFGNode>(node);
572 if (SVFUtil::isExtCall(callNode->getCalledFunction()))
573 {
574 detectExtAPI(callNode);
575 }
576 }
577 else
578 {
579 for (const auto& stmt: node->getSVFStmts())
580 {
581 if (const GepStmt* gep = SVFUtil::dyn_cast<GepStmt>(stmt))
582 {
583 // like llvm bitcode `p = gep p, idx`
584 // we check rhs p's all address are valid mem
585 const ValVar* rhs = gep->getRHSVar();
586 if (!canSafelyDerefPtr(rhs, node))
587 {
588 AEException bug(stmt->toString());
589 addBugToReporter(bug, stmt->getICFGNode());
590 }
591 }
592 else if (const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(stmt))
593 {
594 // like llvm bitcode `p = load q`
595 // we check lhs p's all address are valid mem
596 const ValVar* lhs = load->getLHSVar();
597 if (!canSafelyDerefPtr(lhs, node))
598 {
599 AEException bug(stmt->toString());
600 addBugToReporter(bug, stmt->getICFGNode());
601 }
602 }
603 }
604 }
605}
606
607
609{
610 std::string funcName = callNode->getCalledFunction()->getName();
612 if (funcName == "UNSAFE_LOAD")
613 {
614 // void UNSAFE_LOAD(void* ptr);
615 ae.getUtils()->checkpoints.erase(callNode);
616 if (callNode->arg_size() < 1)
617 return;
618
619 const ValVar* arg0Val = callNode->getArgument(0);
620 // opt may directly dereference a null pointer and call UNSAFE_LOAD(null)
621 bool isSafe = canSafelyDerefPtr(arg0Val, callNode) && arg0Val->getId() != 0;
622 SVFUtil::outs() << "[UNSAFE_LOAD] node=" << callNode->getId()
623 << " arg0=" << arg0Val->getId() << " isSafe=" << isSafe
624 << "\n";
625 if (!isSafe)
626 {
627 SVFUtil::outs() << SVFUtil::sucMsg("success: expected null dereference at UNSAFE_LOAD")
628 << " — " << callNode->toString() << "\n";
629 return;
630 }
631 else
632 {
633 SVFUtil::outs() << SVFUtil::errMsg("failure: null dereference expected at UNSAFE_LOAD, but none detected")
634 << " — Position: " << callNode->getSourceLoc() << "\n";
635 assert(false);
636 }
637 }
638 else if (funcName == "SAFE_LOAD")
639 {
640 // void SAFE_LOAD(void* ptr);
641 ae.getUtils()->checkpoints.erase(callNode);
642 if (callNode->arg_size() < 1) return;
643 const ValVar* arg0Val = callNode->getArgument(0);
644 // opt may directly dereference a null pointer and call UNSAFE_LOAD(null)ols
645 bool isSafe = canSafelyDerefPtr(arg0Val, callNode) && arg0Val->getId() != 0;
646 if (isSafe)
647 {
648 SVFUtil::outs() << SVFUtil::sucMsg("success: expected safe dereference at SAFE_LOAD")
649 << " — " << callNode->toString() << "\n";
650 return;
651 }
652 else
653 {
654 SVFUtil::outs() << SVFUtil::errMsg("failure: unexpected null dereference at SAFE_LOAD")
655 << " — Position: " << callNode->getSourceLoc() << "\n";
656 assert(false);
657 }
658 }
659}
660
662{
663 assert(call->getCalledFunction() && "FunObjVar* is nullptr");
664 // get ext type
665 // get argument index which are nullptr deref checkpoints for extapi
666 std::vector<u32_t> tmp_args;
667 for (const std::string &annotation: ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction()))
668 {
669 if (annotation.find("MEMCPY") != std::string::npos)
670 {
671 if (call->arg_size() < 4)
672 {
673 // for memcpy(void* dest, const void* src, size_t n)
674 tmp_args.push_back(0);
675 tmp_args.push_back(1);
676 }
677 else
678 {
679 // for unsigned long iconv(void* cd, char **restrict inbuf, unsigned long *restrict inbytesleft, char **restrict outbuf, unsigned long *restrict outbytesleft)
680 tmp_args.push_back(1);
681 tmp_args.push_back(2);
682 tmp_args.push_back(3);
683 tmp_args.push_back(4);
684 }
685 }
686 else if (annotation.find("MEMSET") != std::string::npos)
687 {
688 // for memset(void* dest, elem, sz)
689 tmp_args.push_back(0);
690 }
691 else if (annotation.find("STRCPY") != std::string::npos)
692 {
693 // for strcpy(void* dest, void* src)
694 tmp_args.push_back(0);
695 tmp_args.push_back(1);
696 }
697 else if (annotation.find("STRCAT") != std::string::npos)
698 {
699 // for strcat(void* dest, const void* src)
700 // for strncat(void* dest, const void* src, size_t n)
701 tmp_args.push_back(0);
702 tmp_args.push_back(1);
703 }
704 }
705
706 for (const auto &arg: tmp_args)
707 {
708 if (call->arg_size() <= arg)
709 continue;
710 const ValVar* argVal = call->getArgument(arg);
711 if (argVal && !canSafelyDerefPtr(argVal, call))
712 {
713 AEException bug(call->toString());
714 addBugToReporter(bug, call);
715 }
716 }
717}
718
719
721{
723 const AbstractValue& AbsVal = ae.getAbsValue(value, node);
724 if (isUninit(AbsVal)) return false;
725 if (!AbsVal.isAddr()) return true;
726 for (const auto &addr: AbsVal.getAddrs())
727 {
728 // Unknown, null, and freed addresses cannot be safely dereferenced.
730 ae.getAbsState(node).isFreedMem(addr))
731 return false;
732 }
733 return true;
734}
#define BlackHoleObjAddr
buffer offset
Definition cJSON.cpp:1113
Exception class for handling errors in Abstract Execution.
Definition AEDetector.h:112
ExtAPIType
Enumeration of external API types.
Definition AbsExtAPI.h:55
static AbstractInterpretation & getAEInstance()
u32_t getIDFromAddr(u32_t addr) const
Return the internal index if addr is an address otherwise return the value of idx.
static bool isNullOrBlackHoleAddr(u32_t addr)
Whether addr has no concrete backing memory object.
AddressValue & getAddrs()
bool isAddr() const
AddrSet::const_iterator end() const
AddrSet::const_iterator begin() const
const ICFGNode * getICFGNode() const
Get the ICFGNode related to the creation of this object.
bool isConstantByteSize() const
Check if byte size is a const value.
u32_t getByteSizeOfObj() const
Get the byte size of this object.
s64_t getIntNumeral() const
bool detectStrcat(const CallICFGNode *call, BufferOverflowInfo &info)
Detects buffer overflow in 'strcat' function calls.
void addToGepObjOffsetFromBase(const GepObjVar *obj, const IntervalValue &offset)
Adds an offset to a GEP object.
Definition AEDetector.h:203
void detect(const ICFGNode *) override
Detect buffer overflow issues within a node.
Map< std::string, std::vector< std::pair< u32_t, u32_t > > > extAPIBufOverflowCheckRules
Rules for checking buffer overflows in external APIs.
Definition AEDetector.h:342
IntervalValue getAccessOffset(NodeID objId, const GepStmt *gep)
Retrieves the access offset for a given object and GEP statement.
void updateGepObjOffsetFromBase(const ICFGNode *node, AddressValue gepAddrs, AddressValue objAddrs, IntervalValue offset)
Updates the offset of a GEP object from its base.
void detectExtAPI(const CallICFGNode *call)
Handles external API calls related to buffer overflow detection.
IntervalValue getGepObjOffsetFromBase(const GepObjVar *obj) const
Retrieves the offset of a GEP object from its base.
Definition AEDetector.h:223
bool canSafelyAccessMemory(const ValVar *value, const IntervalValue &len, const ICFGNode *node, BufferOverflowInfo *info=nullptr)
Checks if memory can be safely accessed.
void handleStubFunctions(const CallICFGNode *) override
Handles external API calls related to buffer overflow detection.
bool hasGepObjOffsetFromBase(const GepObjVar *obj) const
Checks if a GEP object has an associated offset.
Definition AEDetector.h:213
void initExtAPIBufOverflowCheckRules()
Initializes external API buffer overflow check rules.
void addBugToReporter(const AEException &e, const ICFGNode *node)
Adds a bug to the reporter based on an exception.
Definition AEDetector.h:248
bool detectStrcpy(const CallICFGNode *call, BufferOverflowInfo &info)
Detects buffer overflow in 'strcpy' function calls.
const std::string toString() const override
Definition ICFG.cpp:129
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
Definition ICFGNode.h:483
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:501
const std::string getSourceLoc() const override
Definition ICFGNode.h:571
u32_t arg_size() const
Definition ICFGNode.h:488
static ExtAPI * getExtAPI()
Definition ExtAPI.cpp:43
const SVFStmtList & getSVFStmts() const
Definition ICFGNode.h:116
static bool isNullOrBlkObj(NodeID id)
Check a decoded NodeID, not an AE virtual memory address.
Definition IRGraph.h:169
const BoundedInt & ub() const
Return the upper bound.
bool isBottom() const
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
bool canSafelyDerefPtr(const ValVar *ptr, const ICFGNode *node)
bool isUninit(AbstractValue v)
Checks if an Abstract Value is uninitialized.
Definition AEDetector.h:381
void handleStubFunctions(const CallICFGNode *call) override
Handles external API calls related to nullptr dereferences.
void detect(const ICFGNode *node) override
Detects nullptr dereferences issues within a node.
void addBugToReporter(const AEException &e, const ICFGNode *node)
Adds a bug to the reporter based on an exception.
Definition AEDetector.h:393
void detectExtAPI(const CallICFGNode *call)
Handle external API calls related to nullptr dereferences.
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:499
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:136
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
NodeID getId() const
Get ID.
Definition SVFValue.h:158
virtual const std::string & getName() const
Definition SVFValue.h:184
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
Definition SVFUtil.cpp:75
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
Definition SVFUtil.cpp:98
std::ostream & errs()
Overwrite llvm::errs().
Definition SVFUtil.h:64
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:526
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:76
unsigned u32_t
Definition GeneralType.h:67