A change of external behavior can occur when source code containing a construct having unspecified behavior is recompiled.
Ada: Clause 1.1.5 Bounded error; Clause 3.4.4 unspecified behavior
C: Clause 3.17.3 unspecified behavior
C++: Clause 1.3.13 unspecified behavior
Fortran: ???
CWE: Nothing applicable
See clause 5.1.1.
Language specifications do not always uniquely define the behavior of a construct. When they translate a instance of a construct that is not uniquely defined implementations are permitted to choose from the set of behaviors allowed by the language specification. The term 'unspecified behavior' is sometimes applied to such behaviors, and language specific guidelines need to analyse and document the terms used by their respective language.
It is possible that a developer uses a construct in a way that depends on a subset of the possible behaviors occurring. The behavior of a program containing such a usage is dependent on the translator used to compile it always selecting the 'expected' behavior.
Many language constructs may have unspecified behavior and recommending against use of these constructs may be completely impractical. For instance, in many languages the order of evaluation of the operands appearing on the left- and right-hand side of an assignment statement is unspecified.
The important attribute is not the internal behavior exhibited by a construct (e.g., the sequence of machine code generated by a translator) but its external behavior (i.e., the one visible to a user of a program). If the set of possible unspecified behaviors permitted for a specific use of a construct in source code all produce the same external effect, then a recompilation cannot result in a change of behavior for that specific usage of the construct.
For instance, while the following assignment statement contains unspecified behavior in many languages:
A = B;
in most cases the order in which A
and
B
are evaluated does not effect the external behavior of
a program containing them.
This vulnerability is intended to be applicable to languages with the following characteristics:
Software developers can avoid the vulnerability or mitigate its ill effects in the following ways: