summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2023-06-06 16:25:10 +0100
committerPauli <pauli@openssl.org>2023-07-17 08:17:57 +1000
commit6c1d0e28650164d782909abfea92ba834d0babd5 (patch)
tree9cd43d390aca59a89114111a1568ad2c08699843 /include
parent0911cb4a072f55b5f982635faeaa7a992a14181f (diff)
QUIC CONFORMANCE: Enforce minimal frame type encoding
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/21135)
Diffstat (limited to 'include')
-rw-r--r--include/internal/packet_quic.h18
-rw-r--r--include/internal/quic_wire.h3
2 files changed, 17 insertions, 4 deletions
diff --git a/include/internal/packet_quic.h b/include/internal/packet_quic.h
index 7784e62c16..e75b81e422 100644
--- a/include/internal/packet_quic.h
+++ b/include/internal/packet_quic.h
@@ -40,10 +40,12 @@ __owur static ossl_inline int PACKET_get_quic_vlint(PACKET *pkt,
/*
* Decodes a QUIC variable-length integer in |pkt| and stores the result in
* |data|. Unlike PACKET_get_quic_vlint, this does not advance the current
- * position.
+ * position. If was_minimal is non-NULL, *was_minimal is set to 1 if the integer
+ * was encoded using the minimal possible number of bytes and 0 otherwise.
*/
-__owur static ossl_inline int PACKET_peek_quic_vlint(PACKET *pkt,
- uint64_t *data)
+__owur static ossl_inline int PACKET_peek_quic_vlint_ex(PACKET *pkt,
+ uint64_t *data,
+ int *was_minimal)
{
size_t enclen;
@@ -56,9 +58,19 @@ __owur static ossl_inline int PACKET_peek_quic_vlint(PACKET *pkt,
return 0;
*data = ossl_quic_vlint_decode_unchecked(pkt->curr);
+
+ if (was_minimal != NULL)
+ *was_minimal = (enclen == ossl_quic_vlint_encode_len(*data));
+
return 1;
}
+__owur static ossl_inline int PACKET_peek_quic_vlint(PACKET *pkt,
+ uint64_t *data)
+{
+ return PACKET_peek_quic_vlint_ex(pkt, data, NULL);
+}
+
/*
* Skips over a QUIC variable-length integer in |pkt| without decoding it.
*/
diff --git a/include/internal/quic_wire.h b/include/internal/quic_wire.h
index e9ff8e6f35..8a1ef34ead 100644
--- a/include/internal/quic_wire.h
+++ b/include/internal/quic_wire.h
@@ -493,7 +493,8 @@ int ossl_quic_wire_encode_transport_param_cid(WPACKET *wpkt,
* position). This can be used to determine the frame type and determine which
* frame decoding function to call.
*/
-int ossl_quic_wire_peek_frame_header(PACKET *pkt, uint64_t *type);
+int ossl_quic_wire_peek_frame_header(PACKET *pkt, uint64_t *type,
+ int *was_minimal);
/*
* Like ossl_quic_wire_peek_frame_header, but advances the current position