CWE-242

Use of Inherently Dangerous Function. [Api-Function-Errors, Improper-Adherence-To-Coding-Standards]

Required inputs: IR

The product calls a function that can never be guaranteed to work safely. Certain functions behave in dangerous ways regardless of how they are used. Functions in this category were often implemented without taking security concerns into account. The gets() function is unsafe because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. Similarly, the >> operator is unsafe to use when reading into a statically-allocated character array because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.
Demonstrative Examples
Example 1

The code below calls gets() to read information into a buffer.

Example Language:C
    char buf[BUFSIZE];
    gets(buf);

The gets() function in C is inherently unsafe.

Example 2

The code below calls the gets() function to read in data from the command line.

Example Language:C
        char buf[24];
        printf("Please enter your name and press <Enter>\n");
        gets(buf);
        ...
    }

However, gets() is inherently unsafe, because it copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition.

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

Call to forbidden function.

None

False

Options

blacklist

blacklist

Type: dict[bauhaus.analysis.config.FileGlobPattern, list[bauhaus.analysis.config.GlobPattern]]

Default:

{
   '*stdio.h': ['gets'],
   'io.h': ['vfork'],
   'unistd.h': ['vfork']
}
Dictionary of header globbing to (list of) function name globbing(s) of forbidden functions.