Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

rhel 7
buffer weakness #2


Weakness Breakdown


Buffer overflows are one of the most well-known software vulnerabilities. Even though most developers know what buffer overflows are, attacks against the vulnerabilities are common in both legacy and newer applications. A classic buffer overflow exploit begins with the attacker sending data to a program, which it then stores in an undersized stack buffer. Besides stack buffer overflows, other kinds of buffer overflows include heap overflows, off-by-one errors and many others. Learn more about buffer overflows on OWASP attack index.

Warning code(s):

Easily used incorrectly.

File Name:



The highlighted line of code below is the trigger point of this particular Red Hat Enterprise Linux 7 buffer weakness.

            char* current_dir = (char*)malloc(MOF_PATH_SIZE);
            *current_dir = '\0';
            strncat(current_dir, path, p - path);
            *current_dir_out = current_dir;

	    return stream;

    return NULL;

 * Used to push (and save) the current parsing state and to define a new
 * one from the file_name parameter.
void push_include_file(const char* file_name_)
    // Reverse slashes.

    char file_name[MOF_PATH_SIZE];

    *file_name = '\0';
    strncat(file_name, file_name_, sizeof(file_name) - 1);

    for (char* p = file_name; *p; p++)
        if (*p == '\\')
            *p = '/';

    // Save the old state:

    if (state_stack_size == MAX_STATE_STACK_SIZE)
	MOF_error_printf("includes nested too deeply (greater than %d)",

    MOF_State current_state = 
	{ MOF_file_name, MOF_line_num, MOF_current_dir, YY_CURRENT_BUFFER };

    state_stack[state_stack_size++] = current_state;

    // Open file.

    char* current_dir = NULL;
    FILE* stream = _find_and_open_included_file(file_name, &current_dir);

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.