ebde72
From 8c14927162cf3b4f810683e1c5505e9ef9e1f123 Mon Sep 17 00:00:00 2001
ebde72
From: Eric Covener <covener@apache.org>
ebde72
Date: Wed, 1 Jun 2022 12:34:16 +0000
ebde72
Subject: [PATCH] Merge r1901500 from trunk:
ebde72
ebde72
handle large writes in ap_rputs
ebde72
ebde72
ebde72
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1901501 13f79535-47bb-0310-9956-ffa450edef68
ebde72
---
ebde72
 include/http_protocol.h | 22 +++++++++++++++++++++-
ebde72
 server/protocol.c       |  3 +++
ebde72
 2 files changed, 24 insertions(+), 1 deletion(-)
ebde72
ebde72
diff --git a/include/http_protocol.h b/include/http_protocol.h
ebde72
index 20bd2022266..94c481e5f43 100644
ebde72
--- a/include/http_protocol.h
ebde72
+++ b/include/http_protocol.h
ebde72
@@ -475,7 +475,27 @@ AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
ebde72
  */
ebde72
 static APR_INLINE int ap_rputs(const char *str, request_rec *r)
ebde72
 {
ebde72
-    return ap_rwrite(str, (int)strlen(str), r);
ebde72
+    apr_size_t len;
ebde72
+
ebde72
+    len = strlen(str);
ebde72
+
ebde72
+    for (;;) {
ebde72
+        if (len <= INT_MAX) {
ebde72
+            return ap_rwrite(str, (int)len, r);
ebde72
+        }
ebde72
+        else {
ebde72
+            int rc;
ebde72
+
ebde72
+            rc = ap_rwrite(str, INT_MAX, r);
ebde72
+            if (rc < 0) {
ebde72
+                return rc;
ebde72
+            }
ebde72
+            else {
ebde72
+                str += INT_MAX;
ebde72
+                len -= INT_MAX;
ebde72
+            }
ebde72
+        }
ebde72
+    }
ebde72
 }
ebde72
 
ebde72
 /**
ebde72
diff --git a/server/protocol.c b/server/protocol.c
ebde72
index 298f61e1fb8..7adc7f75c10 100644
ebde72
--- a/server/protocol.c
ebde72
+++ b/server/protocol.c
ebde72
@@ -2128,6 +2128,9 @@ AP_DECLARE(int) ap_rputc(int c, request_rec *r)
ebde72
 
ebde72
 AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
ebde72
 {
ebde72
+    if (nbyte < 0)
ebde72
+        return -1;
ebde72
+
ebde72
     if (r->connection->aborted)
ebde72
         return -1;
ebde72