From 7c5f90353e2e107b9464a73dbdd58e5cc90ec22f Mon Sep 17 00:00:00 2001
From: Christian Hesse <mail@eworm.de>
Date: Wed, 15 Feb 2023 12:22:41 +0100
Subject: [PATCH 1/1] Revert "http2: minor buffer and error path fixes"

This reverts commit 8c762f59983a3e9e2b80fdb34aa5e08f1d9a1c7d.
---
 lib/http2.c                         | 17 ++++-------------
 tests/tests-httpd/test_05_errors.py | 18 +++++++-----------
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/lib/http2.c b/lib/http2.c
index 46fc74645..db968ed2d 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -1905,9 +1905,8 @@ static ssize_t cf_h2_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
 
   if(stream->memlen) {
     ssize_t retlen = stream->memlen;
-
-    /* TODO: all this buffer handling is very brittle */
-    stream->len += stream->memlen;
+    DEBUGF(LOG_CF(data, cf, "[h2sid=%u] recv: returns %zd",
+                  stream->stream_id, retlen));
     stream->memlen = 0;
 
     if(ctx->pause_stream_id == stream->stream_id) {
@@ -1919,10 +1918,6 @@ static ssize_t cf_h2_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
       Curl_expire(data, 0, EXPIRE_RUN_NOW);
     }
     else if(stream->closed) {
-      if(stream->reset || stream->error) {
-        nread = http2_handle_stream_close(cf, data, stream, err);
-        goto out;
-      }
       /* this stream is closed, trigger a another read ASAP to detect that */
       DEBUGF(LOG_CF(data, cf, "[h2sid=%u] is closed now, run again",
                     stream->stream_id));
@@ -1934,15 +1929,11 @@ static ssize_t cf_h2_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
     }
 
     nread = retlen;
-    DEBUGF(LOG_CF(data, cf, "[h2sid=%u] cf_h2_recv -> %zd",
-                  stream->stream_id, nread));
     goto out;
   }
 
-  if(stream->closed) {
-    nread = http2_handle_stream_close(cf, data, stream, err);
-    goto out;
-  }
+  if(stream->closed)
+    return http2_handle_stream_close(cf, data, stream, err);
 
   if(!data->state.drain && Curl_conn_cf_data_pending(cf->next, data)) {
     DEBUGF(LOG_CF(data, cf, "[h2sid=%u] pending data, set drain",
