576df0
diff --git a/modules/metadata/mod_remoteip.c b/modules/metadata/mod_remoteip.c
576df0
index 4572ce1..a0cbc0f 100644
576df0
--- a/modules/metadata/mod_remoteip.c
576df0
+++ b/modules/metadata/mod_remoteip.c
576df0
@@ -987,15 +987,13 @@ static remoteip_parse_status_t remoteip_process_v2_header(conn_rec *c,
576df0
                     return HDR_ERROR;
576df0
 #endif
576df0
                 default:
576df0
-                    /* unsupported protocol, keep local connection address */
576df0
-                    return HDR_DONE;
576df0
+                    /* unsupported protocol */
576df0
+                    ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(10183)
576df0
+                                  "RemoteIPProxyProtocol: unsupported protocol %.2hx",
576df0
+                                  (unsigned short)hdr->v2.fam);
576df0
+                    return HDR_ERROR;
576df0
             }
576df0
             break;  /* we got a sockaddr now */
576df0
-
576df0
-        case 0x00: /* LOCAL command */
576df0
-            /* keep local connection address for LOCAL */
576df0
-            return HDR_DONE;
576df0
-
576df0
         default:
576df0
             /* not a supported command */
576df0
             ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(03507)
576df0
@@ -1087,11 +1085,24 @@ static apr_status_t remoteip_input_filter(ap_filter_t *f,
576df0
     /* try to read a header's worth of data */
576df0
     while (!ctx->done) {
576df0
         if (APR_BRIGADE_EMPTY(ctx->bb)) {
576df0
-            ret = ap_get_brigade(f->next, ctx->bb, ctx->mode, block,
576df0
-                                 ctx->need - ctx->rcvd);
576df0
+            apr_off_t got, want = ctx->need - ctx->rcvd;
576df0
+
576df0
+            ret = ap_get_brigade(f->next, ctx->bb, ctx->mode, block, want);
576df0
             if (ret != APR_SUCCESS) {
576df0
+                ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, f->c, APLOGNO(10184)
576df0
+                              "failed reading input");
576df0
                 return ret;
576df0
             }
576df0
+
576df0
+            ret = apr_brigade_length(ctx->bb, 1, &got;;
576df0
+            if (ret || got > want) {
576df0
+                ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, f->c, APLOGNO(10185)
576df0
+                              "RemoteIPProxyProtocol header too long, "
576df0
+                              "got %" APR_OFF_T_FMT " expected %" APR_OFF_T_FMT,
576df0
+                              got, want);
576df0
+                f->c->aborted = 1;
576df0
+                return APR_ECONNABORTED;
576df0
+            }
576df0
         }
576df0
         if (APR_BRIGADE_EMPTY(ctx->bb)) {
576df0
             return block == APR_NONBLOCK_READ ? APR_SUCCESS : APR_EOF;
576df0
@@ -1139,6 +1150,13 @@ static apr_status_t remoteip_input_filter(ap_filter_t *f,
576df0
                 if (ctx->rcvd >= MIN_V2_HDR_LEN) {
576df0
                     ctx->need = MIN_V2_HDR_LEN +
576df0
                         remoteip_get_v2_len((proxy_header *) ctx->header);
576df0
+                    if (ctx->need > sizeof(proxy_v2)) {
576df0
+                        ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, f->c, APLOGNO(10186)
576df0
+                                      "RemoteIPProxyProtocol protocol header length too long");
576df0
+                        f->c->aborted = 1;
576df0
+                        apr_brigade_destroy(ctx->bb);
576df0
+                        return APR_ECONNABORTED;
576df0
+                    }
576df0
                 }
576df0
                 if (ctx->rcvd >= ctx->need) {
576df0
                     psts = remoteip_process_v2_header(f->c, conn_conf,