CWE-477¶
Use of Obsolete Function. [Api-Function-Errors, Improper-Adherence-To-Coding-Standards]
Required inputs: IR
As programming languages evolve, functions occasionally become obsolete due to:
- Advances in the language
- Improved understanding of how operations should be performed effectively and securely
- Changes in the conventions that govern certain operations
Functions that are removed are usually replaced by newer counterparts that perform the same task in some different and hopefully improved way.
Demonstrative Examples
Example 1
The following code uses the deprecated function getpw() to verify that a plaintext password matches a user's encrypted password. If the password is valid, the function sets result to 1; otherwise it is set to 0.
Example Language:C
...
getpw(uid, pwdline);
for (i=0; i<3; i++){
cryptpw=strtok(pwdline, ":");
pwdline=0;
}
result = strcmp(crypt(plainpw,cryptpw), cryptpw) == 0;
...
Although the code often behaves correctly, using the getpw() function can be problematic from a security standpoint, because it can overflow the buffer passed to its second parameter. Because of this vulnerability, getpw() has been supplanted by getpwuid(), which performs the same lookup as getpw() but returns a pointer to a statically-allocated structure to mitigate the risk. Not all functions are deprecated or replaced because they pose a security risk. However, the presence of an obsolete function often indicates that the surrounding code has been neglected and may be in a state of disrepair. Software security has not been a priority, or even a consideration, for very long. If the program uses deprecated or obsolete functions, it raises the probability that there are security problems lurking nearby.
Example 2
In the following code, the programmer assumes that the system always has a property named "cmd" defined. If an attacker can control the program's environment so that "cmd" is not defined, the program throws a null pointer exception when it attempts to call the "Trim()" method.
Example Language:Java (Unsupported language for documentation only)
String cmd = null;
...
cmd = Environment.GetEnvironmentVariable("cmd");
cmd = cmd.Trim();
Example 3
The following code constructs a string object from an array of bytes and a value that specifies the top 8 bits of each 16-bit Unicode character.
Example Language:Java (Unsupported language for documentation only)
...
String name = new String(nameBytes, highByte);
...
In this example, the constructor may not correctly convert bytes to characters depending upon which charset is used to encode the string represented by nameBytes. Due to the evolution of the charsets used to encode strings, this constructor was deprecated and replaced by a constructor that accepts as one of its parameters the name of the charset used to encode the bytes for conversion.
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
forbidden_libfunc_call |
Do not use deprecated or obsolescent functions. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
blacklist¶
blacklist
Dictionary of header globbing to (list of) function name globbing(s) of forbidden functions.Type: dict[bauhaus.analysis.config.FileGlobPattern, list[bauhaus.analysis.config.GlobPattern]]
Default:
{ 'pwd.h': ['getpw'], 'stdio.h': ['fopen', 'freopen', 'rewind', 'setbuf', 'fprintf', 'fscanf', 'fwprintf', 'fwscanf', 'printf', 'setbuf', 'snprintf', 'sprintf', 'sscanf', 'vfprintf', 'vfscanf', 'vprintf', 'vscanf', 'vsnprintf', 'vsprintf', 'vsscanf', 'wprintf', 'wscanf'], 'stdlib.h': ['atof', 'atoi', 'atol', 'atoll', 'bsearch', 'getenv', 'gmtime', 'mbstowcs', 'qsort', 'wcstombs', 'wctomb', 'wmemcpy'], 'string.h': ['memcpy', 'memmove', 'strcat', 'strcpy', 'strerror', 'strncat', 'strncpy', 'strtok'], 'time.h': ['asctime', 'ctime', 'localtime'], 'wchar.h': ['mbsrtowcs', 'swprintf', 'swscanf', 'vfwprintf', 'vfwscanf', 'vswprintf', 'vswscanf', 'vwprintf', 'vwscanf', 'wcrtomb', 'wcscat', 'wcscpy', 'wcsncat', 'wcsncpy', 'wcsrtombs', 'wcstok', 'wmemmove'] }