libdvbv5: Allocate channel earlier
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Mon, 1 Sep 2014 00:01:56 +0000 (21:01 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Mon, 1 Sep 2014 00:07:43 +0000 (21:07 -0300)
As reported by Coverity:

CID 1228897 (#1 of 1): Explicit null dereferenced (FORWARD_NULL)14. var_deref_model: Passing null pointer channel to get_program_and_store, which dereferences it. [show details]
1129                        rc = get_program_and_store(parms, *dvb_file, dvb_scan_handler,
1130                                                   service_id, channel, NULL,
1131                                                   get_detected, get_nit);

Well, get_program_and_store() explicitly tests if channel is null or
not, but it does it too late.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/libdvbv5/dvb-file.c

index 6d978e6..cfaad31 100644 (file)
@@ -1020,6 +1020,13 @@ static int get_program_and_store(struct dvb_v5_fe_parms_priv *parms,
                if (rc)
                        dvb_logerr("Couldn't get frontend props");
        }
+       if (!*channel) {
+               r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
+               if (r < 0)
+                       dvb_perror("asprintf");
+               if (parms->p.verbose)
+                       dvb_log("Storing as: '%s'", channel);
+       }
        for (j = 0; j < parms->n_props; j++) {
                entry->props[j].cmd = parms->dvb_prop[j].cmd;
                entry->props[j].u.data = parms->dvb_prop[j].u.data;
@@ -1028,14 +1035,6 @@ static int get_program_and_store(struct dvb_v5_fe_parms_priv *parms,
                        freq = parms->dvb_prop[j].u.data;
        }
        entry->n_props = parms->n_props;
-
-       if (!*channel) {
-               r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
-               if (r < 0)
-                       dvb_perror("asprintf");
-               if (parms->p.verbose)
-                       dvb_log("Storing as: '%s'", channel);
-       }
        entry->channel = channel;
 
        if (get_nit)