Changeset e0d922a for lib


Ignore:
Timestamp:
01/11/19 16:24:49 (21 months ago)
Author:
Shane Alcock <salcock@…>
Branches:
develop
Children:
2d16fc7
Parents:
ec19a99
Message:

Make sure ERF packet has a header before trying to access fields in it.

Mainly this will make sure things behave sanely if someone was to
ignore an error returned by trace_read_packet() and try to call
trace_get_capture_length() or some other format-specific function
on the packet anyway.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_erf.c

    rfce4572 re0d922a  
    789789        dag_record_t *erfptr = 0;
    790790        erfptr = (dag_record_t *)packet->header;
    791         uint8_t type = (erfptr->type & 0x7f);
     791        uint8_t type;
     792
     793        if (packet->header == NULL) {
     794                return ~0;
     795        }
     796
     797        type = (erfptr->type & 0x7f);
    792798        if (type != TYPE_LEGACY) {
    793799                /* The top-most bit is now used to indicate the presence of
     
    806812        dag_record_t *erfptr = 0;
    807813        erfptr = (dag_record_t *)packet->header;
    808         return erfptr->flags.iface;
     814        if (packet->header) {
     815                return erfptr->flags.iface;
     816        }
     817        return TRACE_DIR_UNKNOWN;
    809818}
    810819
     
    812821        dag_record_t *erfptr = 0;
    813822        erfptr = (dag_record_t *)packet->header;
     823
     824        if (packet->header == NULL) {
     825                return TRACE_DIR_UNKNOWN;
     826        }
    814827        erfptr->flags.iface = direction;
    815828        return erfptr->flags.iface;
     
    819832        dag_record_t *erfptr = 0;
    820833        erfptr = (dag_record_t *)packet->header;
     834
     835        if (erfptr == NULL) {
     836                return 0;
     837        }
    821838        return bswap_le_to_host64(erfptr->ts);
    822839}
     
    828845        uint16_t wlen, rlen;
    829846
    830         if (packet->payload == NULL)
     847        if (packet->payload == NULL || packet->header == NULL)
    831848                return 0;
    832849
     
    847864        erfptr = (dag_record_t *)packet->header;
    848865
     866        if (packet->header == NULL) {
     867                return 0;
     868        }
     869
    849870        if ((erfptr->type & 0x7f) == TYPE_META)
    850871                return 0;
     
    862883        }
    863884        erfptr = (dag_record_t *)packet->header;
     885
     886        if (packet->header == NULL) {
     887                return ~0U;
     888        }
    864889
    865890        if(size > trace_get_capture_length(packet) || (erfptr->type & 0x7f) == TYPE_META) {
Note: See TracChangeset for help on using the changeset viewer.