arrfab / rpms / httpd

Forked from rpms/httpd 5 years ago
Clone

Blame SOURCES/httpd-2.4.6-r1651653.patch

cce4bc
diff --git a/server/util.c b/server/util.c
cce4bc
index e0ba5c2..a6516d4 100644
cce4bc
--- a/server/util.c
cce4bc
+++ b/server/util.c
cce4bc
@@ -968,20 +968,20 @@ AP_DECLARE(const char *) ap_pcfg_strerror(apr_pool_t *p, ap_configfile_t *cfp,
cce4bc
 /* Read one line from open ap_configfile_t, strip LF, increase line number */
cce4bc
 /* If custom handler does not define a getstr() function, read char by char */
cce4bc
 static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
cce4bc
-                                        ap_configfile_t *cfp)
cce4bc
+                                        apr_size_t offset, ap_configfile_t *cfp)
cce4bc
 {
cce4bc
     apr_status_t rc;
cce4bc
     /* If a "get string" function is defined, use it */
cce4bc
     if (cfp->getstr != NULL) {
cce4bc
         char *cp;
cce4bc
-        char *cbuf = buf;
cce4bc
-        apr_size_t cbufsize = bufsize;
cce4bc
+        char *cbuf = buf + offset;
cce4bc
+        apr_size_t cbufsize = bufsize - offset;
cce4bc
 
cce4bc
         while (1) {
cce4bc
             ++cfp->line_number;
cce4bc
             rc = cfp->getstr(cbuf, cbufsize, cfp->param);
cce4bc
             if (rc == APR_EOF) {
cce4bc
-                if (cbuf != buf) {
cce4bc
+                if (cbuf != buf + offset) {
cce4bc
                     *cbuf = '\0';
cce4bc
                     break;
cce4bc
                 }
cce4bc
@@ -999,11 +999,11 @@ static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
cce4bc
              */
cce4bc
             cp = cbuf;
cce4bc
             cp += strlen(cp);
cce4bc
-            if (cp > cbuf && cp[-1] == LF) {
cce4bc
+            if (cp > buf && cp[-1] == LF) {
cce4bc
                 cp--;
cce4bc
-                if (cp > cbuf && cp[-1] == CR)
cce4bc
+                if (cp > buf && cp[-1] == CR)
cce4bc
                     cp--;
cce4bc
-                if (cp > cbuf && cp[-1] == '\\') {
cce4bc
+                if (cp > buf && cp[-1] == '\\') {
cce4bc
                     cp--;
cce4bc
                     /*
cce4bc
                      * line continuation requested -
cce4bc
@@ -1021,19 +1021,19 @@ static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
cce4bc
         }
cce4bc
     } else {
cce4bc
         /* No "get string" function defined; read character by character */
cce4bc
-        apr_size_t i = 0;
cce4bc
+        apr_size_t i = offset;
cce4bc
 
cce4bc
         if (bufsize < 2) {
cce4bc
             /* too small, assume caller is crazy */
cce4bc
             return APR_EINVAL;
cce4bc
         }
cce4bc
-        buf[0] = '\0';
cce4bc
+        buf[offset] = '\0';
cce4bc
 
cce4bc
         while (1) {
cce4bc
             char c;
cce4bc
             rc = cfp->getch(&c, cfp->param);
cce4bc
             if (rc == APR_EOF) {
cce4bc
-                if (i > 0)
cce4bc
+                if (i > offset)
cce4bc
                     break;
cce4bc
                 else
cce4bc
                     return APR_EOF;
cce4bc
@@ -1051,11 +1051,11 @@ static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
cce4bc
                     break;
cce4bc
                 }
cce4bc
             }
cce4bc
-            else if (i >= bufsize - 2) {
cce4bc
-                return APR_ENOSPC;
cce4bc
-            }
cce4bc
             buf[i] = c;
cce4bc
             ++i;
cce4bc
+            if (i >= bufsize - 1) {
cce4bc
+                return APR_ENOSPC;
cce4bc
+            }
cce4bc
         }
cce4bc
         buf[i] = '\0';
cce4bc
     }
cce4bc
@@ -1089,7 +1089,7 @@ static int cfg_trim_line(char *buf)
cce4bc
 AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, apr_size_t bufsize,
cce4bc
                                         ap_configfile_t *cfp)
cce4bc
 {
cce4bc
-    apr_status_t rc = ap_cfg_getline_core(buf, bufsize, cfp);
cce4bc
+    apr_status_t rc = ap_cfg_getline_core(buf, bufsize, 0, cfp);
cce4bc
     if (rc == APR_SUCCESS)
cce4bc
         cfg_trim_line(buf);
cce4bc
     return rc;
cce4bc
@@ -1116,7 +1116,7 @@ AP_DECLARE(apr_status_t) ap_varbuf_cfg_getline(struct ap_varbuf *vb,
cce4bc
     }
cce4bc
 
cce4bc
     for (;;) {
cce4bc
-        rc = ap_cfg_getline_core(vb->buf + vb->strlen, vb->avail - vb->strlen, cfp);
cce4bc
+        rc = ap_cfg_getline_core(vb->buf, vb->avail, vb->strlen, cfp);
cce4bc
         if (rc == APR_ENOSPC || rc == APR_SUCCESS)
cce4bc
             vb->strlen += strlen(vb->buf + vb->strlen);
cce4bc
         if (rc != APR_ENOSPC)