Skip to content

Commit c3ef6af

Browse files
authored
Merge pull request #9743 from douzzer/20260205-fixes
20260205-fixes
2 parents 1d87187 + 6358320 commit c3ef6af

File tree

4 files changed

+72
-37
lines changed

4 files changed

+72
-37
lines changed

src/ssl_sk.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,50 @@ int wolfSSL_sk_push_node(WOLFSSL_STACK** stack, WOLFSSL_STACK* node)
259259
return ret;
260260
}
261261

262+
/* Pushes the node onto the back of the stack.
263+
*
264+
* If *stack is NULL, node becomes the head.
265+
*
266+
* @param [in, out] stack Stack of nodes.
267+
* @param [in] node Node to append.
268+
*
269+
* @return WOLFSSL_SUCCESS on success
270+
* @return WOLFSSL_FAILURE when stack or node is NULL.
271+
*/
272+
int wolfSSL_sk_push_back_node(WOLFSSL_STACK** stack, WOLFSSL_STACK* node)
273+
{
274+
int ret = WOLFSSL_SUCCESS;
275+
276+
/* Validate parameters. */
277+
if (stack == NULL || node == NULL) {
278+
ret = WOLFSSL_FAILURE;
279+
}
280+
if (ret == WOLFSSL_SUCCESS) {
281+
node->next = NULL;
282+
/* Tail node has num of 1, indicating 1 node till the end */
283+
node->num = 1;
284+
285+
if (*stack == NULL) {
286+
/* First node. */
287+
*stack = node;
288+
}
289+
else {
290+
/* Walk to the end and append. Each node's num field holds the
291+
* count of nodes from that node to the tail (inclusive), so
292+
* every existing node's num increases by one. */
293+
WOLFSSL_STACK* cur = *stack;
294+
while (cur->next != NULL) {
295+
cur->num++;
296+
cur = cur->next;
297+
}
298+
cur->num++;
299+
cur->next = node;
300+
}
301+
}
302+
303+
return ret;
304+
}
305+
262306
/* Removes the node at the index from the stack and returns data.
263307
*
264308
* This is an internal API.

src/x509.c

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14986,50 +14986,38 @@ int wolfSSL_X509_NAME_digest(const WOLFSSL_X509_NAME *name,
1498614986

1498714987
void wolfSSL_X509_email_free(WOLF_STACK_OF(WOLFSSL_STRING) *sk)
1498814988
{
14989-
WOLFSSL_STACK *curr;
14990-
14991-
while (sk != NULL) {
14992-
curr = sk;
14993-
sk = sk->next;
14994-
14995-
XFREE(curr, NULL, DYNAMIC_TYPE_OPENSSL);
14996-
}
14989+
wolfSSL_sk_pop_free(sk, NULL);
1499714990
}
1499814991

14999-
static WOLFSSL_STACK* x509_aia_append_string(WOLFSSL_STACK** head,
14992+
static int x509_aia_append_string(WOLFSSL_STACK** head,
1500014993
const byte* uri, word32 uriSz)
1500114994
{
1500214995
WOLFSSL_STACK* node;
1500314996
char* url;
1500414997

15005-
node = (WOLFSSL_STACK*)XMALLOC(sizeof(WOLFSSL_STACK) + uriSz + 1, NULL,
15006-
DYNAMIC_TYPE_OPENSSL);
15007-
if (node == NULL)
15008-
return NULL;
14998+
url = (char*)XMALLOC(uriSz + 1, NULL, DYNAMIC_TYPE_OPENSSL);
14999+
if (url == NULL)
15000+
return WOLFSSL_FAILURE;
1500915001

15010-
url = (char*)node;
15011-
url += sizeof(WOLFSSL_STACK);
1501215002
XMEMCPY(url, uri, uriSz);
1501315003
url[uriSz] = '\0';
1501415004

15005+
node = wolfSSL_sk_new_node(*head != NULL ? (*head)->heap : NULL);
15006+
if (node == NULL) {
15007+
XFREE(url, NULL, DYNAMIC_TYPE_OPENSSL);
15008+
return WOLFSSL_FAILURE;
15009+
}
15010+
15011+
node->type = STACK_TYPE_STRING;
1501515012
node->data.string = url;
15016-
node->next = NULL;
15017-
node->num = 1;
1501815013

15019-
if (*head == NULL) {
15020-
*head = node;
15021-
}
15022-
else {
15023-
WOLFSSL_STACK* cur = *head;
15024-
while (cur->next != NULL) {
15025-
cur->num++;
15026-
cur = cur->next;
15027-
}
15028-
cur->num++;
15029-
cur->next = node;
15014+
if (wolfSSL_sk_push_back_node(head, node) != WOLFSSL_SUCCESS) {
15015+
XFREE(url, NULL, DYNAMIC_TYPE_OPENSSL);
15016+
wolfSSL_sk_free_node(node);
15017+
return WOLFSSL_FAILURE;
1503015018
}
1503115019

15032-
return node;
15020+
return WOLFSSL_SUCCESS;
1503315021
}
1503415022

1503515023
static WOLFSSL_STACK* x509_get1_aia_by_method(WOLFSSL_X509* x, word32 method,
@@ -15041,8 +15029,8 @@ static WOLFSSL_STACK* x509_get1_aia_by_method(WOLFSSL_X509* x, word32 method,
1504115029
if (x == NULL)
1504215030
return NULL;
1504315031

15044-
/* Build from multi-entry list when available; otherwise fall back to the
15045-
* legacy single-entry fields to preserve previous behavior. */
15032+
/* Collect matching URIs from the multi-entry list into a new stack;
15033+
* fall back to the legacy single-entry field for compatibility. */
1504615034
if (x->authInfoListSz > 0) {
1504715035
for (i = 0; i < x->authInfoListSz; i++) {
1504815036
if (x->authInfoList[i].method != method ||
@@ -15052,15 +15040,16 @@ static WOLFSSL_STACK* x509_get1_aia_by_method(WOLFSSL_X509* x, word32 method,
1505215040
}
1505315041

1505415042
if (x509_aia_append_string(&head, x->authInfoList[i].uri,
15055-
x->authInfoList[i].uriSz) == NULL) {
15056-
wolfSSL_X509_email_free(head);
15043+
x->authInfoList[i].uriSz) != WOLFSSL_SUCCESS) {
15044+
wolfSSL_sk_pop_free(head, NULL);
1505715045
return NULL;
1505815046
}
1505915047
}
1506015048
}
1506115049
if (head == NULL && fallback != NULL && fallbackSz > 0) {
15062-
if (x509_aia_append_string(&head, fallback, (word32)fallbackSz) == NULL) {
15063-
wolfSSL_X509_email_free(head);
15050+
if (x509_aia_append_string(&head, fallback, (word32)fallbackSz)
15051+
!= WOLFSSL_SUCCESS) {
15052+
wolfSSL_sk_pop_free(head, NULL);
1506415053
return NULL;
1506515054
}
1506615055
}

wolfssl/ssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,8 @@ WOLFSSL_API WOLFSSL_STACK* wolfSSL_sk_get_node(WOLFSSL_STACK* sk, int idx);
19171917
#endif
19181918
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)
19191919
WOLFSSL_API int wolfSSL_sk_push_node(WOLFSSL_STACK** stack, WOLFSSL_STACK* in);
1920+
WOLFSSL_API int wolfSSL_sk_push_back_node(WOLFSSL_STACK** stack,
1921+
WOLFSSL_STACK* in);
19201922

19211923
WOLFSSL_API void wolfSSL_sk_free(WOLFSSL_STACK* sk);
19221924
WOLFSSL_API WOLFSSL_STACK* wolfSSL_sk_dup(WOLFSSL_STACK* sk);

wolfssl/wolfcrypt/asn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,8 +2075,8 @@ struct DecodedCert {
20752075
#endif /* WOLFSSL_DUAL_ALG_CERTS */
20762076

20772077
WOLFSSL_AIA_ENTRY extAuthInfoList[WOLFSSL_MAX_AIA_ENTRIES];
2078-
byte extAuthInfoListSz:7;
2079-
byte extAuthInfoListOverflow:1;
2078+
WC_BITFIELD extAuthInfoListSz:7;
2079+
WC_BITFIELD extAuthInfoListOverflow:1;
20802080
};
20812081

20822082
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)

0 commit comments

Comments
 (0)