* the tag value is html decoded if dodecode is non-zero
*/
-static char *get_tag(pool *p, FILE *in, char *tag, int tagbuf_len, int dodecode)
+static char *get_tag(request_rec *r, FILE *in, char *tag, int tagbuf_len, int dodecode)
{
char *t = tag, *tag_val, c, term;
+ pool *p = r->pool;
/* makes code below a little less cluttered */
--tagbuf_len;
/* find end of tag name */
while (1) {
- if (t - tag == tagbuf_len) {
+ if (t == tag + tagbuf_len) {
*t = '\0';
return NULL;
}
term = c;
while (1) {
GET_CHAR(in, c, NULL, p);
- if (t - tag == tagbuf_len) {
+ if (t == tag + tagbuf_len) {
*t = '\0';
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
+ "mod_include: value length exceeds limit"
+ " (%d) in %s", tagbuf_len, r->filename);
return NULL;
}
-/* Want to accept \" as a valid character within a string. */
+ /* Want to accept \" as a valid character within a string. */
if (c == '\\') {
- *(t++) = c; /* Add backslash */
GET_CHAR(in, c, NULL, p);
- if (c == term) { /* Only if */
- *(--t) = c; /* Replace backslash ONLY for terminator */
+ /* Insert backslash only if not escaping a terminator char */
+ if (c != term) {
+ *(t++) = '\\';
+ /*
+ * check to make sure that adding in the backslash won't cause
+ * an overflow, since we're now 1 character ahead.
+ */
+ if (t == tag + tagbuf_len) {
+ *t = '\0';
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
+ "mod_include: value length exceeds limit"
+ " (%d) in %s", tagbuf_len, r->filename);
+ return NULL;
+ }
}
}
else if (c == term) {
return ap_pstrdup(p, tag_val);
}
-static int get_directive(FILE *in, char *dest, size_t len, pool *p)
+static int get_directive(FILE *in, char *dest, size_t len, request_rec *r)
{
char *d = dest;
+ pool *p = r->pool;
char c;
/* make room for nul terminator */
/* now get directive */
while (1) {
if (d == len + dest) {
+ ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
+ "mod_include: directive length exceeds limit"
+ " (%d) in %s", len+1, r->filename);
return 1;
}
*d++ = ap_tolower(c);
char *tag_val;
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
if (!strcmp(tag, "file") || !strcmp(tag, "virtual")) {
char parsed_string[MAX_STRING_LEN];
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
if (!strcmp(tag, "cmd")) {
encode = E_ENTITY;
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
if (!strcmp(tag, "var")) {
return DECLINED;
}
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
break;
}
if (strnEQ(tag, "sub", 3)) {
table *env = r->subprocess_env;
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 0))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 0))) {
return 1;
}
if (!strcmp(tag, "errmsg")) {
char parsed_string[MAX_STRING_LEN];
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
else if (!strcmp(tag, "done")) {
char parsed_string[MAX_STRING_LEN];
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
else if (!strcmp(tag, "done")) {
expr = NULL;
while (1) {
- tag_val = get_tag(r->pool, in, tag, sizeof(tag), 0);
+ tag_val = get_tag(r, in, tag, sizeof(tag), 0);
if (!tag_val || *tag == '\0') {
return 1;
}
expr = NULL;
while (1) {
- tag_val = get_tag(r->pool, in, tag, sizeof(tag), 0);
+ tag_val = get_tag(r, in, tag, sizeof(tag), 0);
if (!tag_val || *tag == '\0') {
return 1;
}
{
char tag[MAX_STRING_LEN];
- if (!get_tag(r->pool, in, tag, sizeof(tag), 1)) {
+ if (!get_tag(r, in, tag, sizeof(tag), 1)) {
return 1;
}
else if (!strcmp(tag, "done")) {
{
char tag[MAX_STRING_LEN];
- if (!get_tag(r->pool, in, tag, sizeof(tag), 1)) {
+ if (!get_tag(r, in, tag, sizeof(tag), 1)) {
return 1;
}
else if (!strcmp(tag, "done")) {
var = (char *) NULL;
while (1) {
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
else if (!strcmp(tag, "done")) {
table_entry *elts = (table_entry *) arr->elts;
int i;
- if (!(tag_val = get_tag(r->pool, in, tag, sizeof(tag), 1))) {
+ if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) {
return 1;
}
else if (!strcmp(tag, "done")) {
while (1) {
if (!find_string(f, STARTING_SEQUENCE, r, printing)) {
- if (get_directive(f, directive, sizeof(directive), r->pool)) {
- ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
- "mod_include: error reading directive in %s",
- r->filename);
+ if (get_directive(f, directive, sizeof(directive), r)) {
ap_rputs(error, r);
return;
}