View | Details | Raw Unified | Return to bug 55910
Collapse All | Expand All

(-)a/server/util.c (-15 / +15 lines)
Lines 971-990 AP_DECLARE(const char *) ap_pcfg_strerror(apr_pool_t *p, ap_configfile_t *cfp, Link Here
971
/* Read one line from open ap_configfile_t, strip LF, increase line number */
971
/* Read one line from open ap_configfile_t, strip LF, increase line number */
972
/* If custom handler does not define a getstr() function, read char by char */
972
/* If custom handler does not define a getstr() function, read char by char */
973
static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
973
static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize,
974
                                        ap_configfile_t *cfp)
974
                                        apr_size_t offset, ap_configfile_t *cfp)
975
{
975
{
976
    apr_status_t rc;
976
    apr_status_t rc;
977
    /* If a "get string" function is defined, use it */
977
    /* If a "get string" function is defined, use it */
978
    if (cfp->getstr != NULL) {
978
    if (cfp->getstr != NULL) {
979
        char *cp;
979
        char *cp;
980
        char *cbuf = buf;
980
        char *cbuf = buf + offset;
981
        apr_size_t cbufsize = bufsize;
981
        apr_size_t cbufsize = bufsize - offset;
982
982
983
        while (1) {
983
        while (1) {
984
            ++cfp->line_number;
984
            ++cfp->line_number;
985
            rc = cfp->getstr(cbuf, cbufsize, cfp->param);
985
            rc = cfp->getstr(cbuf, cbufsize, cfp->param);
986
            if (rc == APR_EOF) {
986
            if (rc == APR_EOF) {
987
                if (cbuf != buf) {
987
                if (cbuf != buf + offset) {
988
                    *cbuf = '\0';
988
                    *cbuf = '\0';
989
                    break;
989
                    break;
990
                }
990
                }
Lines 1002-1012 static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize, Link Here
1002
             */
1002
             */
1003
            cp = cbuf;
1003
            cp = cbuf;
1004
            cp += strlen(cp);
1004
            cp += strlen(cp);
1005
            if (cp > cbuf && cp[-1] == LF) {
1005
            if (cp > buf && cp[-1] == LF) {
1006
                cp--;
1006
                cp--;
1007
                if (cp > cbuf && cp[-1] == CR)
1007
                if (cp > buf && cp[-1] == CR)
1008
                    cp--;
1008
                    cp--;
1009
                if (cp > cbuf && cp[-1] == '\\') {
1009
                if (cp > buf && cp[-1] == '\\') {
1010
                    cp--;
1010
                    cp--;
1011
                    /*
1011
                    /*
1012
                     * line continuation requested -
1012
                     * line continuation requested -
Lines 1024-1042 static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize, Link Here
1024
        }
1024
        }
1025
    } else {
1025
    } else {
1026
        /* No "get string" function defined; read character by character */
1026
        /* No "get string" function defined; read character by character */
1027
        apr_size_t i = 0;
1027
        apr_size_t i = offset;
1028
1028
1029
        if (bufsize < 2) {
1029
        if (bufsize < 2) {
1030
            /* too small, assume caller is crazy */
1030
            /* too small, assume caller is crazy */
1031
            return APR_EINVAL;
1031
            return APR_EINVAL;
1032
        }
1032
        }
1033
        buf[0] = '\0';
1033
        buf[offset] = '\0';
1034
1034
1035
        while (1) {
1035
        while (1) {
1036
            char c;
1036
            char c;
1037
            rc = cfp->getch(&c, cfp->param);
1037
            rc = cfp->getch(&c, cfp->param);
1038
            if (rc == APR_EOF) {
1038
            if (rc == APR_EOF) {
1039
                if (i > 0)
1039
                if (i > offset)
1040
                    break;
1040
                    break;
1041
                else
1041
                else
1042
                    return APR_EOF;
1042
                    return APR_EOF;
Lines 1054-1064 static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize, Link Here
1054
                    break;
1054
                    break;
1055
                }
1055
                }
1056
            }
1056
            }
1057
            else if (i >= bufsize - 2) {
1058
                return APR_ENOSPC;
1059
            }
1060
            buf[i] = c;
1057
            buf[i] = c;
1061
            ++i;
1058
            ++i;
1059
            if (i >= bufsize - 1) {
1060
                return APR_ENOSPC;
1061
            }
1062
        }
1062
        }
1063
        buf[i] = '\0';
1063
        buf[i] = '\0';
1064
    }
1064
    }
Lines 1092-1098 static int cfg_trim_line(char *buf) Link Here
1092
AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, apr_size_t bufsize,
1092
AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, apr_size_t bufsize,
1093
                                        ap_configfile_t *cfp)
1093
                                        ap_configfile_t *cfp)
1094
{
1094
{
1095
    apr_status_t rc = ap_cfg_getline_core(buf, bufsize, cfp);
1095
    apr_status_t rc = ap_cfg_getline_core(buf, bufsize, 0, cfp);
1096
    if (rc == APR_SUCCESS)
1096
    if (rc == APR_SUCCESS)
1097
        cfg_trim_line(buf);
1097
        cfg_trim_line(buf);
1098
    return rc;
1098
    return rc;
Lines 1119-1125 AP_DECLARE(apr_status_t) ap_varbuf_cfg_getline(struct ap_varbuf *vb, Link Here
1119
    }
1119
    }
1120
1120
1121
    for (;;) {
1121
    for (;;) {
1122
        rc = ap_cfg_getline_core(vb->buf + vb->strlen, vb->avail - vb->strlen, cfp);
1122
        rc = ap_cfg_getline_core(vb->buf, vb->avail, vb->strlen, cfp);
1123
        if (rc == APR_ENOSPC || rc == APR_SUCCESS)
1123
        if (rc == APR_ENOSPC || rc == APR_SUCCESS)
1124
            vb->strlen += strlen(vb->buf + vb->strlen);
1124
            vb->strlen += strlen(vb->buf + vb->strlen);
1125
        if (rc != APR_ENOSPC)
1125
        if (rc != APR_ENOSPC)

Return to bug 55910