85cb4d
--- a/modules/proxy/mod_proxy_uwsgi.c	2020/07/24 09:31:46	1880250
85cb4d
+++ b/modules/proxy/mod_proxy_uwsgi.c	2020/07/24 09:35:25	1880251
85cb4d
@@ -136,7 +136,7 @@
85cb4d
     int j;
85cb4d
 
85cb4d
     apr_size_t headerlen = 4;
85cb4d
-    apr_uint16_t pktsize, keylen, vallen;
85cb4d
+    apr_size_t pktsize, keylen, vallen;
85cb4d
     const char *script_name;
85cb4d
     const char *path_info;
85cb4d
     const char *auth;
85cb4d
@@ -178,6 +178,15 @@
85cb4d
         headerlen += 2 + strlen(env[j].key) + 2 + strlen(env[j].val);
85cb4d
     }
85cb4d
 
85cb4d
+    pktsize = headerlen - 4;
85cb4d
+    if (pktsize > APR_UINT16_MAX) {
85cb4d
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10259)
85cb4d
+                      "can't send headers to %s:%u: packet size too "
85cb4d
+                      "large (%" APR_SIZE_T_FMT ")",
85cb4d
+                      conn->hostname, conn->port, pktsize);
85cb4d
+        return HTTP_INTERNAL_SERVER_ERROR;
85cb4d
+    }
85cb4d
+
85cb4d
     ptr = buf = apr_palloc(r->pool, headerlen);
85cb4d
 
85cb4d
     ptr += 4;
85cb4d
@@ -196,8 +205,6 @@
85cb4d
         ptr += vallen;
85cb4d
     }
85cb4d
 
85cb4d
-    pktsize = headerlen - 4;
85cb4d
-
85cb4d
     buf[0] = 0;
85cb4d
     buf[1] = (apr_byte_t) (pktsize & 0xff);
85cb4d
     buf[2] = (apr_byte_t) ((pktsize >> 8) & 0xff);