]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - ssl/quic/quic_rx_depack.c
Rationalize FIPS sources
[thirdparty/openssl.git] / ssl / quic / quic_rx_depack.c
index da941dc10393488041e29b40c6b68d17b5d3fe6a..939df84c9dd881c109aa331d394a51046e3fd012 100644 (file)
@@ -7,7 +7,7 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include "internal/packet.h"
+#include "internal/packet_quic.h"
 #include "internal/nelem.h"
 #include "internal/quic_wire.h"
 #include "internal/quic_record_rx.h"
@@ -111,11 +111,20 @@ static int depack_do_frame_reset_stream(PACKET *pkt,
     ackm_data->is_ack_eliciting = 1;
 
     stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
-    if (stream == NULL || stream->rstream == NULL) {
+    if (stream == NULL) {
         ossl_quic_channel_raise_protocol_error(ch,
                                                QUIC_ERR_STREAM_STATE_ERROR,
                                                OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
-                                               "RESET_STREAM frame for nonexistent or "
+                                               "RESET_STREAM frame for "
+                                               "nonexistent stream");
+        return 0;
+    }
+
+    if (stream->rstream == NULL) {
+        ossl_quic_channel_raise_protocol_error(ch,
+                                               QUIC_ERR_STREAM_STATE_ERROR,
+                                               OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
+                                               "RESET_STREAM frame for "
                                                "TX only stream");
         return 0;
     }
@@ -144,11 +153,20 @@ static int depack_do_frame_stop_sending(PACKET *pkt,
     ackm_data->is_ack_eliciting = 1;
 
     stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
-    if (stream == NULL || stream->sstream == NULL) {
+    if (stream == NULL) {
         ossl_quic_channel_raise_protocol_error(ch,
                                                QUIC_ERR_STREAM_STATE_ERROR,
                                                OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
-                                               "STOP_SENDING frame for nonexistent or "
+                                               "STOP_SENDING frame for "
+                                               "nonexistent stream");
+        return 0;
+    }
+
+    if (stream->sstream == NULL) {
+        ossl_quic_channel_raise_protocol_error(ch,
+                                               QUIC_ERR_STREAM_STATE_ERROR,
+                                               OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
+                                               "STOP_SENDING frame for "
                                                "RX only stream");
         return 0;
     }
@@ -235,12 +253,21 @@ static int depack_do_frame_stream(PACKET *pkt, QUIC_CHANNEL *ch,
     ackm_data->is_ack_eliciting = 1;
 
     stream = ossl_quic_stream_map_get_by_id(&ch->qsm, frame_data.stream_id);
-    if (stream == NULL || stream->rstream == NULL) {
+    if (stream == NULL) {
         ossl_quic_channel_raise_protocol_error(ch,
                                                QUIC_ERR_STREAM_STATE_ERROR,
                                                frame_type,
-                                               "STREAM frame for nonexistent or"
-                                               " TX only stream");
+                                               "STREAM frame for nonexistent "
+                                               "stream");
+        return 0;
+    }
+
+    if (stream->rstream == NULL) {
+        ossl_quic_channel_raise_protocol_error(ch,
+                                               QUIC_ERR_STREAM_STATE_ERROR,
+                                               frame_type,
+                                               "STREAM frame for TX only "
+                                               "stream");
         return 0;
     }
 
@@ -323,12 +350,21 @@ static int depack_do_frame_max_stream_data(PACKET *pkt,
     ackm_data->is_ack_eliciting = 1;
 
     stream = ossl_quic_stream_map_get_by_id(&ch->qsm, stream_id);
-    if (stream == NULL || stream->sstream == NULL) {
+    if (stream == NULL) {
+        ossl_quic_channel_raise_protocol_error(ch,
+                                               QUIC_ERR_STREAM_STATE_ERROR,
+                                               OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA,
+                                               "MAX_STREAM_DATA for nonexistent "
+                                               "stream");
+        return 0;
+    }
+
+    if (stream->sstream == NULL) {
         ossl_quic_channel_raise_protocol_error(ch,
                                                QUIC_ERR_STREAM_STATE_ERROR,
                                                OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA,
-                                               "MAX_STREAM_DATA for nonexistent"
-                                               " or TX only stream");
+                                               "MAX_STREAM_DATA for TX only "
+                                               "stream");
         return 0;
     }
 
@@ -364,28 +400,28 @@ static int depack_do_frame_max_streams(PACKET *pkt,
     }
 
     switch (frame_type) {
-        case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI:
-            if (max_streams > ch->max_local_streams_bidi)
-                ch->max_local_streams_bidi = max_streams;
+    case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI:
+        if (max_streams > ch->max_local_streams_bidi)
+            ch->max_local_streams_bidi = max_streams;
 
-            /* Stream may now be able to send */
-            ossl_quic_stream_map_update_state(&ch->qsm,
-                                              ch->stream0);
-            break;
-        case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI:
-            if (max_streams > ch->max_local_streams_uni)
-                ch->max_local_streams_uni = max_streams;
+        /* Stream may now be able to send */
+        ossl_quic_stream_map_update_state(&ch->qsm,
+                                          ch->stream0);
+        break;
+    case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI:
+        if (max_streams > ch->max_local_streams_uni)
+            ch->max_local_streams_uni = max_streams;
 
-            /* Stream may now be able to send */
-            ossl_quic_stream_map_update_state(&ch->qsm,
-                                              ch->stream0);
-            break;
-        default:
-            ossl_quic_channel_raise_protocol_error(ch,
-                                                   QUIC_ERR_FRAME_ENCODING_ERROR,
-                                                   frame_type,
-                                                   "decode error");
-            return 0;
+        /* Stream may now be able to send */
+        ossl_quic_stream_map_update_state(&ch->qsm,
+                                          ch->stream0);
+        break;
+    default:
+        ossl_quic_channel_raise_protocol_error(ch,
+                                               QUIC_ERR_FRAME_ENCODING_ERROR,
+                                               frame_type,
+                                               "decode error");
+        return 0;
     }
 
     return 1;