Language: C
Label: safe
CWE: CWE-120 \u2014 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.

Code:
Tss2_RC_Decode(TSS2_RC rc)
{
    static __thread char buf[TSS2_ERR_LAYER_NAME_MAX + TSS2_ERR_LAYER_ERROR_STR_MAX + 1];

    clearbuf(buf);

    UINT8 layer = tss2_rc_layer_number_get(rc);

    TSS2_RC_HANDLER handler = layer_handler[layer].handler;
    const char *lname = layer_handler[layer].name;

    if (lname[0]) {
        catbuf(buf, "%s:", lname);
    } else {
        catbuf(buf, "%u:", layer);
    }

    /*
     * Handlers only need the error bits. This way they don't
     * need to concern themselves with masking off the layer
     * bits or anything else.
     */
    if (handler) {
        UINT16 err_bits = tpm2_error_get(rc);
        const char *e = err_bits ? handler(err_bits) : "success";
        if (e) {
            catbuf(buf, "%s", e);
        } else {
            catbuf(buf, "0x%X", err_bits);
        }
    } else {
        /*
         * we don't want to drop any bits if we don't know what to do with it
         * so drop the layer byte since we we already have that.
         */
        const char *e = unknown_layer_handler(rc >> 8);
        assert(e);
        catbuf(buf, "%s", e);
    }

    return buf;
}