Skip to content

Conversation

nickrolfe
Copy link
Contributor

s/manger/manager

Pull Request checklist

All query authors

Internal query authors only

  • Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • Adding a new query? Consider also adding the query to autofix.

@nickrolfe nickrolfe added the no-change-note-required This PR does not need a change note label Nov 19, 2024
@nickrolfe nickrolfe requested a review from a team as a code owner November 19, 2024 17:42
Copy link
Contributor

QHelp previews:

cpp/ql/src/Critical/UseAfterFree.qhelp

Potential use after free

This rule finds accesses through a pointer of a memory location that has already been freed (i.e. through a dangling pointer). Such memory blocks have already been released to the dynamic memory manager, and modifying them can lead to anything from a segfault to memory corruption that would cause subsequent calls to the dynamic memory manager to behave erratically, to a possible security vulnerability.

WARNING: This check is an approximation, so some results may not be actual defects in the program. It is not possible in general to compute the values of pointers without running the program with all input data.

Recommendation

Ensure that all execution paths that access memory through a pointer never access that pointer after it is freed.

Example

void f() {
	char* buf = new char[SIZE];
	...
	if (error) {
		delete buf; //error handling has freed the buffer
	}
	...
	log_contents(buf); //but it is still used here for logging
	...
}

References

  • I. Gerg. An Overview and Example of the Buffer-Overflow Exploit. IANewsletter vol 7 no 4. 2005.
  • M. Donaldson. Inside the Buffer Overflow Attack: Mechanism, Method & Prevention. SANS Institute InfoSec Reading Room. 2002.
  • Common Weakness Enumeration: CWE-416.

@jketema jketema merged commit 5a18f1f into main Nov 19, 2024
11 of 12 checks passed
@jketema jketema deleted the nickrolfe/typo-manger branch November 19, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ documentation no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants