Skip to content

Commit 22717a4

Browse files
committed
Address copilot feedback
1 parent 0f30790 commit 22717a4

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/ssl_asn1.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,11 +1016,14 @@ int wolfSSL_ASN1_INTEGER_get_length(const WOLFSSL_ASN1_INTEGER* ai)
10161016
if (ai->data[0] == ASN_INTEGER) {
10171017
word32 idx = 1;
10181018
int len = 0;
1019-
if (GetLength(ai->data, &idx, &len, (word32)ai->length) > 0) {
1019+
if (GetLength(ai->data, &idx, &len, (word32)ai->length) > 0 &&
1020+
idx + (word32)len == (word32)ai->length) {
10201021
return len;
10211022
}
10221023
}
1023-
/* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header */
1024+
/* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1025+
* or data that coincidentally starts with 0x02 but whose header+value
1026+
* boundaries do not span exactly ai->length. */
10241027
return ai->length;
10251028
}
10261029

@@ -1040,11 +1043,14 @@ const unsigned char* wolfSSL_ASN1_INTEGER_get0_data(const WOLFSSL_ASN1_INTEGER*
10401043
if (ai->data[0] == ASN_INTEGER) {
10411044
word32 idx = 1;
10421045
int len = 0;
1043-
if (GetLength(ai->data, &idx, &len, (word32)ai->length) > 0) {
1046+
if (GetLength(ai->data, &idx, &len, (word32)ai->length) > 0 &&
1047+
idx + (word32)len == (word32)ai->length) {
10441048
return ai->data + idx;
10451049
}
10461050
}
1047-
/* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header */
1051+
/* WOLFSSL_QT / WOLFSSL_HAPROXY format: raw bytes without DER header,
1052+
* or data that coincidentally starts with 0x02 but whose header+value
1053+
* boundaries do not span exactly ai->length. */
10481054
return ai->data;
10491055
}
10501056

wolfssl/openssl/ssl.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,25 +1022,23 @@ wolfSSL_X509_STORE_set_verify_cb((WOLFSSL_X509_STORE *)(s), (WOLFSSL_X509_STORE_
10221022
#define ASN1_STRING_cmp wolfSSL_ASN1_STRING_cmp
10231023
#define ASN1_OCTET_STRING_cmp wolfSSL_ASN1_STRING_cmp
10241024
#define ASN1_STRING_data wolfSSL_ASN1_STRING_data
1025-
/* In OpenSSL, ASN1_INTEGER and ASN1_BIT_STRING are typedef aliases of
1026-
* ASN1_STRING (same struct), so ASN1_STRING_length/get0_data work on all.
1025+
/* In OpenSSL, ASN1_INTEGER is a typedef alias of ASN1_STRING (same struct),
1026+
* so ASN1_STRING_length/get0_data work on ASN1_INTEGER* as well.
10271027
* In wolfSSL they are distinct structs, so dispatch by type using _Generic. */
10281028
#if !defined(__cplusplus) && defined(__STDC_VERSION__) && \
10291029
__STDC_VERSION__ >= 201112L
1030-
#define ASN1_STRING_length(x) _Generic((x), \
1031-
WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get_length( \
1032-
(const WOLFSSL_ASN1_INTEGER*)(x)), \
1033-
const WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get_length( \
1034-
(const WOLFSSL_ASN1_INTEGER*)(x)), \
1035-
default: wolfSSL_ASN1_STRING_length( \
1036-
(const WOLFSSL_ASN1_STRING*)(x)))
1037-
#define ASN1_STRING_get0_data(x) _Generic((x), \
1038-
WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get0_data( \
1039-
(const WOLFSSL_ASN1_INTEGER*)(x)), \
1040-
const WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get0_data( \
1041-
(const WOLFSSL_ASN1_INTEGER*)(x)), \
1042-
default: wolfSSL_ASN1_STRING_get0_data( \
1043-
(const WOLFSSL_ASN1_STRING*)(x)))
1030+
#define ASN1_STRING_length(x) \
1031+
_Generic((x), \
1032+
WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get_length, \
1033+
const WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get_length, \
1034+
default: wolfSSL_ASN1_STRING_length \
1035+
)(x)
1036+
#define ASN1_STRING_get0_data(x) \
1037+
_Generic((x), \
1038+
WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get0_data, \
1039+
const WOLFSSL_ASN1_INTEGER*: wolfSSL_ASN1_INTEGER_get0_data, \
1040+
default: wolfSSL_ASN1_STRING_get0_data \
1041+
)(x)
10441042
#else
10451043
#define ASN1_STRING_get0_data wolfSSL_ASN1_STRING_get0_data
10461044
#define ASN1_STRING_length wolfSSL_ASN1_STRING_length

0 commit comments

Comments
 (0)