uhttpd/file: fix string out of buffer range on uh_defer_script
[project/uhttpd.git] / relay.c
diff --git a/relay.c b/relay.c
index 619534970c7c5b948031b877a50e52aa7138b103..6db58acac786910896f24184b16d6b326d6ca632 100644 (file)
--- a/relay.c
+++ b/relay.c
@@ -142,7 +142,9 @@ static void relay_read_cb(struct ustream *s, int bytes)
        if (!buf || !len)
                return;
 
-       uh_chunk_write(cl, buf, len);
+       if (!r->skip_data)
+               uh_chunk_write(cl, buf, len);
+
        ustream_consume(s, len);
 }
 
@@ -153,7 +155,7 @@ static void relay_close_if_done(struct uloop_timeout *timeout)
 
        while (ustream_poll(&r->sfd.stream));
 
-       if (!(r->process_done || s->eof) || ustream_pending_data(s, false))
+       if (!(r->process_done || s->eof) || (ustream_pending_data(s, false) && !r->header_cb))
                return;
 
        uh_relay_close(r, r->ret);