@@ -25002,31 +25002,69 @@ int wc_ParseCert(DecodedCert* cert, int type, int verify, void* cm)
2500225002 return ParseCert(cert, type, verify, cm);
2500325003}
2500425004
25005- const char* wc_GetDecodedCertSubject(struct DecodedCert* cert, word32* subjectSz)
25005+ int wc_GetDecodedCertSubject(const struct DecodedCert* cert, char* buf,
25006+ word32* bufSz)
2500625007{
25007- if (cert == NULL || subjectSz == NULL) {
25008- return NULL;
25008+ word32 sz;
25009+
25010+ if (cert == NULL || bufSz == NULL)
25011+ return BAD_FUNC_ARG;
25012+
25013+ sz = (word32)XSTRLEN(cert->subject);
25014+
25015+ if (buf == NULL) {
25016+ *bufSz = sz;
25017+ return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
2500925018 }
25010- *subjectSz = (word32)XSTRLEN(cert->subject);
25011- return cert->subject;
25019+
25020+ if (*bufSz < sz)
25021+ return BUFFER_E;
25022+
25023+ XMEMCPY(buf, cert->subject, sz);
25024+ *bufSz = sz;
25025+ return 0;
2501225026}
2501325027
25014- const char* wc_GetDecodedCertIssuer(struct DecodedCert* cert, word32* issuerSz)
25028+ int wc_GetDecodedCertIssuer(const struct DecodedCert* cert, char* buf,
25029+ word32* bufSz)
2501525030{
25016- if (cert == NULL || issuerSz == NULL) {
25017- return NULL;
25031+ word32 sz;
25032+
25033+ if (cert == NULL || bufSz == NULL)
25034+ return BAD_FUNC_ARG;
25035+
25036+ sz = (word32)XSTRLEN(cert->issuer);
25037+
25038+ if (buf == NULL) {
25039+ *bufSz = sz;
25040+ return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
2501825041 }
25019- *issuerSz = (word32)XSTRLEN(cert->issuer);
25020- return cert->issuer;
25042+
25043+ if (*bufSz < sz)
25044+ return BUFFER_E;
25045+
25046+ XMEMCPY(buf, cert->issuer, sz);
25047+ *bufSz = sz;
25048+ return 0;
2502125049}
2502225050
25023- const byte* wc_GetDecodedCertSerial(struct DecodedCert* cert, word32* serialSz)
25051+ int wc_GetDecodedCertSerial(const struct DecodedCert* cert, byte* buf,
25052+ word32* bufSz)
2502425053{
25025- if (cert == NULL || serialSz == NULL) {
25026- return NULL;
25054+ if (cert == NULL || bufSz == NULL)
25055+ return BAD_FUNC_ARG;
25056+
25057+ if (buf == NULL) {
25058+ *bufSz = (word32)cert->serialSz;
25059+ return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
2502725060 }
25028- *serialSz = (word32)cert->serialSz;
25029- return cert->serial;
25061+
25062+ if (*bufSz < (word32)cert->serialSz)
25063+ return BUFFER_E;
25064+
25065+ XMEMCPY(buf, cert->serial, (size_t)cert->serialSz);
25066+ *bufSz = (word32)cert->serialSz;
25067+ return 0;
2503025068}
2503125069
2503225070#ifdef WOLFCRYPT_ONLY
0 commit comments