~oisf/suricata-daily-git-libhtp-0.5.x/libhtp

« back to all changes in this revision

Viewing changes to htp/htp_response.c

  • Committer: Victor Julien
  • Date: 2020-10-05 09:49:38 UTC
  • Revision ID: git-v1:5093d5e4b43ecfcc411c5de130cb901f3a7bab7f
response/chunked: code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
    return HTP_DATA;
343
343
}
344
344
 
345
 
#define HTP_CHUNKED_ISCTLCHAR(c) ((c) == 0x0d || (c) == 0x0a || (c) == 0x20 || (c) == 0x09 || (c) == 0x0b || (c) == 0x0c)
 
345
static inline int is_chunked_ctl_char(const unsigned char c) {
 
346
    switch (c) {
 
347
        case 0x0d:
 
348
        case 0x0a:
 
349
        case 0x20:
 
350
        case 0x09:
 
351
        case 0x0b:
 
352
        case 0x0c:
 
353
            return 1;
 
354
        default:
 
355
            return 0;
 
356
    }
 
357
}
 
358
 
346
359
/**
347
360
 * Peeks ahead into the data to try to see if it starts with a valid Chunked
348
361
 * length field.
362
375
    while (i < len) {
363
376
        unsigned char c = data[i];
364
377
 
365
 
        if (HTP_CHUNKED_ISCTLCHAR(c)) {
 
378
        if (is_chunked_ctl_char(c)) {
366
379
            // ctl char, still good.
367
380
        } else if (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
368
381
            // real chunklen char
387
400
        OUT_COPY_BYTE_OR_RETURN(connp);
388
401
 
389
402
        // Have we reached the end of the line? Or is this not chunked after all?
390
 
        if (connp->out_next_byte == LF || (!HTP_CHUNKED_ISCTLCHAR(connp->out_next_byte) &&!data_probe_chunk_length(connp))) {
 
403
        if (connp->out_next_byte == LF ||
 
404
                (!is_chunked_ctl_char(connp->out_next_byte) && !data_probe_chunk_length(connp))) {
391
405
            unsigned char *data;
392
406
            size_t len;
393
407