Mutable Objects Passed by Reference
Weakness ID: 374 (Weakness Base)Status: Draft
+ Description

Description Summary

Sending non-cloned mutable data as an argument may result in that data being altered or deleted by the called function, thereby putting the calling function into an undefined state.
+ Time of Introduction
  • Implementation
+ Applicable Platforms






+ Common Consequences

Potentially data could be tampered with by another function which should not have been tampered with.

+ Likelihood of Exploit


+ Demonstrative Examples

Example 1

(Bad Code)
Example Languages: C and C++ 
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.

+ Potential Mitigations

Phase: Implementation

Pass in data which should not be altered as constant or immutable.

Phase: Implementation

Clone all mutable data before returning references to it. 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.

+ Other Notes

In situations where unknown code is called with references to mutable data, this external code may possibly make changes to the data sent. If this data was not previously cloned, you will be left with modified data which may, or may not, be valid in the context of execution.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory371State Issues
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class668Exposure of Resource to Wrong Sphere
Research Concepts (primary)1000
+ Taxonomy Mappings
Mapped Taxonomy NameNode IDFitMapped Node Name
CLASPMutable objects passed by reference
+ Content History
Submission DateSubmitterOrganizationSource
CLASPExternally Mined
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Applicable Platforms, Common Consequences, Relationships, Other Notes, Taxonomy Mappings