Incorrect Control Flow Scoping

The product does not properly return control flow to the proper location after it has completed a task or detected an unusual condition.


The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

The following example attempts to resolve a hostname.

protected void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException {
  String ip = req.getRemoteAddr();
  InetAddress addr = InetAddress.getByName(ip);
  out.println("hello " + addr.getHostName());

A DNS lookup failure will cause the Servlet to throw an exception.

Example Two

This code queries a server and displays its status when a request comes from an authorized IP address.

$requestingIP = $_SERVER['REMOTE_ADDR'];
  echo "You are not authorized to view this page";
$status = getServerStatus();
echo $status;

This code redirects unauthorized users, but continues to execute code after calling http_redirect(). This means even unauthorized users may be able to access the contents of the page or perform a DoS attack on the server being queried. Also, note that this code is vulnerable to an IP address spoofing attack (CWE-212).

Example Three

Included in the doPost() method defined below is a call to System.exit() in the event of a specific exception.

Public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  try {
  } catch (ApplicationSpecificException ase) {
    logger.error("Caught: " + ase.toString());

See Also

Comprehensive Categorization: Insufficient Control Flow Management

Weaknesses in this category are related to insufficient control flow management.

SEI CERT Perl Coding Standard - Guidelines 03. Expressions (EXP)

Weaknesses in this category are related to the rules and recommendations in the Expressions (EXP) section of the SEI CERT Perl Coding Standard.

SEI CERT C Coding Standard - Guidelines 10. Environment (ENV)

Weaknesses in this category are related to the rules and recommendations in the Environment (ENV) section of the SEI CERT C Coding Standard.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Weaknesses Introduced During Implementation

This view (slice) lists weaknesses that can be introduced during implementation.

Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.