stack smashing detected resolution process

The figure problems in the implementation of the program after the end of the return 0. The main reason is the presence of an array of cross-border in the program.

Solution:

See the definition of structures in the body 1. The buffer size of 4096 bytes

 typedef struct
    {
        UINT32 len;
        BYTE buf[4096];
    } ctrust_tpm2_combuf_t
 

2. Check the structure to be stored TPMS_CONTEXT size of 5208 bytes

  
  sizeof(TPMS_CONTEXT)

 

3. When memcpy copy byte size restrictions to be added

     
   if (sizeof(TPMS_CONTEXT) > 4096)
        {
            sub_context->len = 4096;
        }
        else
        {
            sub_context->len = sizeof(TPMS_CONTEXT);
        }
  memcpy(&sub_context->buf, (BYTE *)&context, sub_context->len);

 

 

Guess you like

Origin www.cnblogs.com/wenkyme/p/11988620.html