]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: fix NULL->field_len access
authorVincent JARDIN <vincent.jardin@6wind.com>
Mon, 9 Oct 2017 10:42:11 +0000 (12:42 +0200)
committerVincent JARDIN <vincent.jardin@6wind.com>
Mon, 9 Oct 2017 10:42:11 +0000 (12:42 +0200)
Currenlty, this function is used only by:
  - unit test of csv.c (see its main() section)
  - ptm_lib.c

In case of ptm, it is safe to return NULL because:
  csv_encode_record() -> return NULL
     _ptm_lib_encode_header() -> return NULL
        the only consumer of the return value is: ptm_lib_init_msg()
        that checks the NULL return.

Warning:
  Access to field 'field_len' results in a dereference of a null
  pointer (loaded from variable 'fld')

Signed-off-by: Vincent Jardin <vincent.jardin@6wind.com>
lib/csv.c

index 0ad5c74be34aa40b76fa7e2ff990a7a56987a31b..45582e30922559ed5085fcb6d0ef2aa939adc95e 100644 (file)
--- a/lib/csv.c
+++ b/lib/csv.c
@@ -284,6 +284,8 @@ csv_record_t *csv_encode_record(csv_t *csv, csv_record_t *rec, int count, ...)
 
        va_start(list, count);
        str = csv_field_iter(rec, &fld);
+       if (!fld)
+               return NULL;
        for (tempc = 0; tempc < count; tempc++) {
                col = va_arg(list, char *);
                for (i = 0; i < fld->field_len; i++) {