snagarajan206118 (Community Member) asked a question.

How to fix CWE ID 416 - Use After Free in c++?

In my c++ application, I want to return a char buffer from a method. I received CWE 416 vulnerability.

 

ConfigCoreStrings* WrapperGetCoreConfigString()

{

    char* buffer;

    unsigned int buffer_size = (1024 * 128);

buffer = (char*)malloc(buffer_size);

if (buffer == NULL)

        {

          free(wGetCoreConfigString);

        }

memset(buffer, 0, buffer_size); //Line where the vulnerablity indicates

}

 

 

I tried putting memset(buffer, 0, buffer_size); inside else case, but didn't help. Any suggestions??


Topics (3)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.