Get a line of protocol input, including any continuation lines * caused by MIME folding (or broken clients) if fold != 0, and place it * in the buffer s, of size n bytes, without the ending newline. * * Pulls from r->proto_input_filters instead of r->input_filters for * stricter protocol adherence and better input filter behavior during * chunked trailer processing (for http). * * If s is
| 214 | * or a full buffer, that's considered an error. |
| 215 | */ |
| 216 | AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n, |
| 217 | apr_size_t *read, request_rec *r, |
| 218 | int flags, apr_bucket_brigade *bb) |
| 219 | { |
| 220 | apr_status_t rv; |
| 221 | apr_bucket *e; |
| 222 | apr_size_t bytes_handled = 0, current_alloc = 0; |
| 223 | char *pos, *last_char = *s; |
| 224 | int do_alloc = (*s == NULL), saw_eos = 0; |
| 225 | int fold = flags & AP_GETLINE_FOLD; |
| 226 | int crlf = flags & AP_GETLINE_CRLF; |
| 227 | int nospc_eol = flags & AP_GETLINE_NOSPC_EOL; |
| 228 | int saw_eol = 0, saw_nospc = 0; |
| 229 | |
| 230 | if (!n) { |
| 231 | /* Needs room for NUL byte at least */ |
| 232 | *read = 0; |
| 233 | return APR_BADARG; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Initialize last_char as otherwise a random value will be compared |
| 238 | * against APR_ASCII_LF at the end of the loop if bb only contains |
| 239 | * zero-length buckets. |
| 240 | */ |
| 241 | if (last_char) |
| 242 | *last_char = '\0'; |
| 243 | |
| 244 | do { |
| 245 | apr_brigade_cleanup(bb); |
| 246 | rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_GETLINE, |
| 247 | APR_BLOCK_READ, 0); |
| 248 | if (rv != APR_SUCCESS) { |
| 249 | goto cleanup; |
| 250 | } |
| 251 | |
| 252 | /* Something horribly wrong happened. Someone didn't block! |
| 253 | * (this also happens at the end of each keepalive connection) |
| 254 | */ |
| 255 | if (APR_BRIGADE_EMPTY(bb)) { |
| 256 | rv = APR_EGENERAL; |
| 257 | goto cleanup; |
| 258 | } |
| 259 | |
| 260 | for (e = APR_BRIGADE_FIRST(bb); |
| 261 | e != APR_BRIGADE_SENTINEL(bb); |
| 262 | e = APR_BUCKET_NEXT(e)) |
| 263 | { |
| 264 | const char *str; |
| 265 | apr_size_t len; |
| 266 | |
| 267 | /* If we see an EOS, don't bother doing anything more. */ |
| 268 | if (APR_BUCKET_IS_EOS(e)) { |
| 269 | saw_eos = 1; |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ); |
no test coverage detected