forked from wolfSSL/wolfssl
Push/pop to/from the end of the list object
The last object pushed should be visible in the highest index
This commit is contained in:
@@ -14743,14 +14743,14 @@ int wolfSSL_sk_push(WOLFSSL_STACK* sk, const void *data)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_sk_push");
|
||||
|
||||
return wolfSSL_sk_insert(sk, data, 0);
|
||||
return wolfSSL_sk_insert(sk, data, -1);
|
||||
}
|
||||
|
||||
void* wolfSSL_sk_pop(WOLFSSL_STACK* sk)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_sk_pop");
|
||||
|
||||
return wolfSSL_sk_pop_node(sk, 0);
|
||||
return wolfSSL_sk_pop_node(sk, -1);
|
||||
}
|
||||
|
||||
/* return number of elements on success 0 on fail */
|
||||
|
58
src/x509.c
58
src/x509.c
@@ -4230,38 +4230,7 @@ WOLFSSL_X509* wolfSSL_sk_X509_value(WOLF_STACK_OF(WOLFSSL_X509)* sk, int i)
|
||||
/* Return and remove the first x509 pushed on stack */
|
||||
WOLFSSL_X509* wolfSSL_sk_X509_shift(WOLF_STACK_OF(WOLFSSL_X509)* sk)
|
||||
{
|
||||
WOLFSSL_STACK* node;
|
||||
WOLFSSL_X509* x509;
|
||||
|
||||
if (sk == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = sk->next;
|
||||
x509 = sk->data.x509;
|
||||
|
||||
if (node != NULL) {
|
||||
/* walk to end of stack to first node pushed, and remove it */
|
||||
WOLFSSL_STACK* prevNode = sk;
|
||||
|
||||
while (node->next != NULL) {
|
||||
prevNode = node;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
x509 = node->data.x509;
|
||||
prevNode->next = NULL;
|
||||
XFREE(node, NULL, DYNAMIC_TYPE_X509);
|
||||
}
|
||||
else { /* only one x509 in stack */
|
||||
sk->data.x509 = NULL;
|
||||
}
|
||||
|
||||
if (sk->num > 0) {
|
||||
sk->num -= 1;
|
||||
}
|
||||
|
||||
return x509;
|
||||
return wolfSSL_sk_pop_node(sk, 0);
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_EXTRA */
|
||||
@@ -15318,7 +15287,6 @@ WOLFSSL_X509_ATTRIBUTE *wolfSSL_X509_REQ_get_attr(
|
||||
int wolfSSL_X509_REQ_get_attr_by_NID(const WOLFSSL_X509 *req,
|
||||
int nid, int lastpos)
|
||||
{
|
||||
WOLFSSL_STACK* sk;
|
||||
int idx;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_X509_REQ_get_attr_by_NID");
|
||||
@@ -15329,26 +15297,14 @@ int wolfSSL_X509_REQ_get_attr_by_NID(const WOLFSSL_X509 *req,
|
||||
}
|
||||
|
||||
/* search through stack for first matching nid */
|
||||
idx = lastpos + 1;
|
||||
do {
|
||||
sk = wolfSSL_sk_get_node(req->reqAttributes, idx);
|
||||
if (sk != NULL) {
|
||||
WOLFSSL_X509_ATTRIBUTE* attr;
|
||||
attr = (WOLFSSL_X509_ATTRIBUTE*)sk->data.generic;
|
||||
if (nid == attr->object->nid) {
|
||||
/* found a match */
|
||||
break;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
} while (sk != NULL);
|
||||
|
||||
/* no matches found */
|
||||
if (sk == NULL) {
|
||||
idx = WOLFSSL_FATAL_ERROR;
|
||||
for (idx = lastpos + 1; idx < wolfSSL_sk_num(req->reqAttributes); idx++) {
|
||||
WOLFSSL_X509_ATTRIBUTE* attr =
|
||||
(WOLFSSL_X509_ATTRIBUTE*)wolfSSL_sk_value(req->reqAttributes, idx);
|
||||
if (attr != NULL && attr->object != NULL && attr->object->nid == nid)
|
||||
return idx;
|
||||
}
|
||||
|
||||
return idx;
|
||||
return WOLFSSL_FATAL_ERROR;
|
||||
}
|
||||
|
||||
WOLFSSL_X509_ATTRIBUTE* wolfSSL_X509_ATTRIBUTE_new(void)
|
||||
|
36
tests/api.c
36
tests/api.c
@@ -22069,7 +22069,7 @@ static int test_wolfSSL_X509_INFO_multiple_info(void)
|
||||
ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
|
||||
ExpectNotNull(info->x509);
|
||||
ExpectNull(info->crl);
|
||||
if (i != 0) {
|
||||
if (i != 2) {
|
||||
ExpectNotNull(info->x_pkey);
|
||||
ExpectIntEQ(X509_check_private_key(info->x509,
|
||||
info->x_pkey->dec_pkey), 1);
|
||||
@@ -36213,7 +36213,7 @@ static int test_GENERAL_NAME_set0_othername(void)
|
||||
|
||||
ExpectNull(sk_GENERAL_NAME_value(NULL, 0));
|
||||
ExpectNull(sk_GENERAL_NAME_value(gns, 20));
|
||||
ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
|
||||
ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
|
||||
ExpectIntEQ(gn->type, 0);
|
||||
|
||||
sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
|
||||
@@ -46197,8 +46197,8 @@ static int test_sk_X509(void)
|
||||
sk_X509_push(s, &x2);
|
||||
ExpectIntEQ(sk_X509_num(s), 2);
|
||||
ExpectNull(sk_X509_value(s, 2));
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == &x2), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 1) == &x1), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == &x1), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 1) == &x2), 1);
|
||||
sk_X509_push(s, &x2);
|
||||
|
||||
sk_X509_pop_free(s, free_x509);
|
||||
@@ -46223,20 +46223,20 @@ static int test_sk_X509(void)
|
||||
for (i = 0; i < len; ++i) {
|
||||
sk_X509_push(s, xList[i]);
|
||||
ExpectIntEQ(sk_X509_num(s), i + 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == xList[0]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, i) == xList[i]), 1);
|
||||
}
|
||||
|
||||
/* pop returns and removes last pushed on stack, which is index 0
|
||||
/* pop returns and removes last pushed on stack, which is the last index
|
||||
* in sk_x509_value */
|
||||
for (i = 0; i < len; ++i) {
|
||||
X509 * x = sk_X509_value(s, 0);
|
||||
for (i = len-1; i >= 0; --i) {
|
||||
X509 * x = sk_X509_value(s, i);
|
||||
X509 * y = sk_X509_pop(s);
|
||||
X509 * z = xList[len - 1 - i];
|
||||
X509 * z = xList[i];
|
||||
|
||||
ExpectIntEQ((x == y), 1);
|
||||
ExpectIntEQ((x == z), 1);
|
||||
ExpectIntEQ(sk_X509_num(s), len - 1 - i);
|
||||
ExpectPtrEq(x, y);
|
||||
ExpectPtrEq(x, z);
|
||||
ExpectIntEQ(sk_X509_num(s), i);
|
||||
}
|
||||
|
||||
sk_free(s);
|
||||
@@ -46248,14 +46248,14 @@ static int test_sk_X509(void)
|
||||
for (i = 0; i < len; ++i) {
|
||||
sk_X509_push(s, xList[i]);
|
||||
ExpectIntEQ(sk_X509_num(s), i + 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, 0) == xList[0]), 1);
|
||||
ExpectIntEQ((sk_X509_value(s, i) == xList[i]), 1);
|
||||
}
|
||||
|
||||
/* shift returns and removes first pushed on stack, which is index i
|
||||
* in sk_x509_value() */
|
||||
for (i = 0; i < len; ++i) {
|
||||
X509 * x = sk_X509_value(s, len - 1 - i);
|
||||
X509 * x = sk_X509_value(s, 0);
|
||||
X509 * y = sk_X509_shift(s);
|
||||
X509 * z = xList[i];
|
||||
|
||||
@@ -49234,12 +49234,12 @@ static int test_wolfSSL_d2i_X509_REQ(void)
|
||||
ExpectIntEQ(X509_REQ_get_attr_by_NID(NULL, NID_pkcs9_challengePassword,
|
||||
-1), -1);
|
||||
ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
|
||||
-1), 1);
|
||||
-1), 0);
|
||||
ExpectNull(X509_REQ_get_attr(NULL, 3));
|
||||
ExpectNull(X509_REQ_get_attr(req, 3));
|
||||
ExpectNull(X509_REQ_get_attr(NULL, 0));
|
||||
ExpectNull(X509_REQ_get_attr(empty, 0));
|
||||
ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
|
||||
ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
|
||||
ExpectNull(X509_ATTRIBUTE_get0_type(NULL, 1));
|
||||
ExpectNull(X509_ATTRIBUTE_get0_type(attr, 1));
|
||||
ExpectNull(X509_ATTRIBUTE_get0_type(NULL, 0));
|
||||
|
Reference in New Issue
Block a user