| 1068 | } |
| 1069 | |
| 1070 | static int do_errorlog_format(apr_array_header_t *fmt, ap_errorlog_info *info, |
| 1071 | char *buf, int buflen, int *errstr_start, |
| 1072 | int *errstr_end, const char *err_fmt, va_list args) |
| 1073 | { |
| 1074 | #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED |
| 1075 | char scratch[MAX_STRING_LEN]; |
| 1076 | #endif |
| 1077 | int i; |
| 1078 | int len = 0; |
| 1079 | int field_start = 0; |
| 1080 | int skipping = 0; |
| 1081 | ap_errorlog_format_item *items = (ap_errorlog_format_item *)fmt->elts; |
| 1082 | |
| 1083 | AP_DEBUG_ASSERT(fmt->nelts > 0); |
| 1084 | for (i = 0; i < fmt->nelts; ++i) { |
| 1085 | ap_errorlog_format_item *item = &items[i]; |
| 1086 | if (item->flags & AP_ERRORLOG_FLAG_FIELD_SEP) { |
| 1087 | if (skipping) { |
| 1088 | skipping = 0; |
| 1089 | } |
| 1090 | else { |
| 1091 | field_start = len; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) { |
| 1096 | /* the actual error message */ |
| 1097 | *errstr_start = len; |
| 1098 | #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED |
| 1099 | if (apr_vsnprintf(scratch, MAX_STRING_LEN, err_fmt, args)) { |
| 1100 | len += ap_escape_errorlog_item(buf + len, scratch, |
| 1101 | buflen - len); |
| 1102 | |
| 1103 | } |
| 1104 | #else |
| 1105 | len += apr_vsnprintf(buf + len, buflen - len, err_fmt, args); |
| 1106 | #endif |
| 1107 | *errstr_end = len; |
| 1108 | } |
| 1109 | else if (skipping) { |
| 1110 | continue; |
| 1111 | } |
| 1112 | else if (info->level != -1 && (int)item->min_loglevel > info->level) { |
| 1113 | len = field_start; |
| 1114 | skipping = 1; |
| 1115 | } |
| 1116 | else { |
| 1117 | int item_len = (*item->func)(info, item->arg, buf + len, |
| 1118 | buflen - len); |
| 1119 | if (!item_len) { |
| 1120 | if (item->flags & AP_ERRORLOG_FLAG_REQUIRED) { |
| 1121 | /* required item is empty. skip whole line */ |
| 1122 | buf[0] = '\0'; |
| 1123 | return 0; |
| 1124 | } |
| 1125 | else if (item->flags & AP_ERRORLOG_FLAG_NULL_AS_HYPHEN) { |
| 1126 | buf[len++] = '-'; |
| 1127 | } |
no test coverage detected