Function Call with Incorrectly Specified Arguments

The product calls a function, procedure, or routine with arguments that are not correctly specified, leading to always-incorrect behavior and resultant weaknesses.


Description

There are multiple ways in which this weakness can be introduced, including:

the wrong variable or reference;

an incorrect number of arguments;

incorrect order of arguments;

wrong type of arguments; or

wrong value.

Demonstrations

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 PHP method authenticates a user given a username/password combination but is called with the parameters in reverse order.

function authenticate($username, $password) {


  // authenticate user
  ...

}

authenticate($_POST['password'], $_POST['username']);

Example Two

This Perl code intends to record whether a user authenticated successfully or not, and to exit if the user fails to authenticate. However, when it calls ReportAuth(), the third argument is specified as 0 instead of 1, so it does not exit.

sub ReportAuth {
  my ($username, $result, $fatal) = @_;
  PrintLog("auth: username=%s, result=%d", $username, $result);
  if (($result ne "success") && $fatal) {
    die "Failed!\n";
  }
}

sub PrivilegedFunc
{
  my $result = CheckAuth($username);
  ReportAuth($username, $result, 0);
  DoReallyImportantStuff();
}

Example Three

In the following Java snippet, the accessGranted() method is accidentally called with the static ADMIN_ROLES array rather than the user roles.

private static final String[] ADMIN_ROLES = ...;
public boolean void accessGranted(String resource, String user) {
  String[] userRoles = getUserRoles(user);
  return accessGranted(resource, ADMIN_ROLES);
}

private boolean void accessGranted(String resource, String[] userRoles) {


  // grant or deny access based on user roles
  ...

}

See Also

Comprehensive Categorization: Poor Coding Practices

Weaknesses in this category are related to poor coding practices.

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 Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL)

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

Comprehensive CWE Dictionary

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

CWE Cross-section

This view contains a selection of weaknesses that represent the variety of weaknesses that are captured in CWE, at a level of abstraction that is likely to be useful t...

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.