921
Applicable Platforms
Language : C (Prevalence = Undetermined)
Language : C++ (Prevalence = Undetermined)
Language : Java (Prevalence = Undetermined)
Language : C# (Prevalence = Undetermined)
Likelihood Of Exploit
Medium
Common Consequences
Scope Impact Likelihood
Integrity Modify Memory
Potentially data could be tampered with by another
function which should not have been tampered with.
Potential Mitigations
Phase: Implementation
Pass in data which should not be altered as constant or immutable.
Phase: Implementation
Clone all mutable data before passing it into an external function . This is the preferred
mitigation. This way, regardless of what changes are made to the data, a valid copy is retained
for use by the class.
Demonstrative Examples
Example 1:
The following example demonstrates the weakness.
Example Language: C (Bad)
private:
int foo;
complexType bar;
String baz;
otherClass externalClass;
public:
void doStuff() {
externalClass.doOtherStuff(foo, bar, baz)
}
In this example, bar and baz will be passed by reference to doOtherStuff() which may change
them.
Example 2:
In the following Java example, the BookStore class manages the sale of books in a bookstore,
this class includes the member objects for the bookstore inventory and sales database manager
classes. The BookStore class includes a method for updating the sales database and inventory
when a book is sold. This method retrieves a Book object from the bookstore inventory object using
the supplied ISBN number for the book class, then calls a method for the sales object to update
the sales information and then calls a method for the inventory object to update inventory for the
BookStore.
Example Language: Java (Bad)
public class BookStore {
private BookStoreInventory inventory;
CWE Version 4.14
CWE-374: Passing Mutable Objects to an Untrusted Method
CWE-374: Passing Mutable Objects to an Untrusted Method