int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
                             const void *data, int len)
{
    ASN1_TYPE *ttmp;
    ASN1_STRING *stmp = NULL;
    int atype = 0;
    if (!attr)
        return 0;
    if (attrtype & MBSTRING_FLAG) {
        stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
                                      OBJ_obj2nid(attr->object));
        if (!stmp) {
            X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);
            return 0;
        }
        atype = stmp->type;
    } else if (len != -1) {
        if ((stmp = ASN1_STRING_type_new(attrtype)) == NULL)
            goto err;
        if (!ASN1_STRING_set(stmp, data, len))
            goto err;
        atype = attrtype;
    }
    if (attrtype == 0)
        return 1;
    if ((ttmp = ASN1_TYPE_new()) == NULL)
        goto err;
    if ((len == -1) && !(attrtype & MBSTRING_FLAG)) {
        if (!ASN1_TYPE_set1(ttmp, attrtype, data))
            goto err;
    } else
        ASN1_TYPE_set(ttmp, atype, stmp);
    if (!sk_ASN1_TYPE_push(attr->set, ttmp))
        goto err;
    return 1;
 err:
    X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
    return 0;
}
['int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,\n                             const void *data, int len)\n{\n    ASN1_TYPE *ttmp;\n    ASN1_STRING *stmp = NULL;\n    int atype = 0;\n    if (!attr)\n        return 0;\n    if (attrtype & MBSTRING_FLAG) {\n        stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,\n                                      OBJ_obj2nid(attr->object));\n        if (!stmp) {\n            X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_ASN1_LIB);\n            return 0;\n        }\n        atype = stmp->type;\n    } else if (len != -1) {\n        if ((stmp = ASN1_STRING_type_new(attrtype)) == NULL)\n            goto err;\n        if (!ASN1_STRING_set(stmp, data, len))\n            goto err;\n        atype = attrtype;\n    }\n    if (attrtype == 0)\n        return 1;\n    if ((ttmp = ASN1_TYPE_new()) == NULL)\n        goto err;\n    if ((len == -1) && !(attrtype & MBSTRING_FLAG)) {\n        if (!ASN1_TYPE_set1(ttmp, attrtype, data))\n            goto err;\n    } else\n        ASN1_TYPE_set(ttmp, atype, stmp);\n    if (!sk_ASN1_TYPE_push(attr->set, ttmp))\n        goto err;\n    return 1;\n err:\n    X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);\n    return 0;\n}', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n    ASN1_STRING *ret;\n    ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n        ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->type = type;\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n    unsigned char *c;\n    const char *data = _data;\n    if (len < 0) {\n        if (data == NULL)\n            return (0);\n        else\n            len = strlen(data);\n    }\n    if ((str->length < len) || (str->data == NULL)) {\n        c = str->data;\n        str->data = OPENSSL_realloc(c, len + 1);\n        if (str->data == NULL) {\n            ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n            str->data = c;\n            return (0);\n        }\n    }\n    str->length = len;\n    if (data != NULL) {\n        memcpy(str->data, data, len);\n        str->data[len] = '\\0';\n    }\n    return (1);\n}", 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    (void)file;\n    (void)line;\n#endif\n    return realloc(str, num);\n}']