Skip to contentSkip to conversation

libdvbv5: cleanup logging, some memory checks

PATCH New André Roth 1 participant 2 messages Sep 13, 2014 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libdvbv5: cleanup logging, some memory checks

- use loginfo in hexdump
- use C comments
- memory checking in desc_sat and desc_service

---
 lib/include/libdvbv5/desc_service_list.h |  3 +-
 lib/libdvbv5/descriptors.c               |  2 +-
 lib/libdvbv5/descriptors/desc_sat.c      | 12 +++++---
 lib/libdvbv5/descriptors/desc_service.c  | 50 ++++++++++++++++++++++++++------
 4 files changed, 52 insertions(+), 15 deletions(-)
lib/include/libdvbv5/desc_service_list.h +2 -1
index e08ea3c..1773ebd 100644
@@ -34,7 +34,8 @@ struct dvb_desc_service_list {
 	uint8_t length;
 	struct dvb_desc *next;
 
-	//struct dvb_desc_service_list_table services[];
+	/* FIXME */
+	/* struct dvb_desc_service_list_table services[]; */
 } __attribute__((packed));
 
 struct dvb_v5_fe_parms;
lib/libdvbv5/descriptors.c +1 -1
index eaee148..63ce939 100644
@@ -1345,7 +1345,7 @@ void dvb_hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsign
 			strncat(hex, " ", sizeof(hex) - 1);
 		if (j == 16) {
 			ascii[j] = '\0';
-			dvb_log("%s%s  %s", prefix, hex, ascii);
+			dvb_loginfo("%s%s  %s", prefix, hex, ascii);
 			j = 0;
 			hex[0] = '\0';
 		}
lib/libdvbv5/descriptors/desc_sat.c +8 -4
index 326f534..7268239 100644
@@ -25,10 +25,14 @@
 int dvb_desc_sat_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
 {
 	struct dvb_desc_sat *sat = (struct dvb_desc_sat *) desc;
-	/* copy from .length */
-	memcpy(((uint8_t *) sat ) + sizeof(sat->type) + sizeof(sat->next) + sizeof(sat->length),
-		buf,
-		sat->length);
+	ssize_t size = sizeof(struct dvb_desc_sat) - sizeof(struct dvb_desc);
+
+	if (size > desc->length) {
+		dvb_logerr("dvb_desc_sat_init short read %d/%zd bytes", desc->length, size);
+		return -1;
+	}
+
+	memcpy(desc->data, buf, size);
 	bswap16(sat->orbit);
 	bswap32(sat->bitfield);
 	bswap32(sat->frequency);
lib/libdvbv5/descriptors/desc_service.c +41 -9

68 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 libdvbv5: fix satellite LNBf handling

the LNBf is part of the public structure, remove it from dvb_v5_fe_parms_priv.

fix typo for C++.

---
 lib/include/libdvbv5/dvb-sat.h | 2 +-
 lib/libdvbv5/dvb-fe-priv.h     | 1 -
 lib/libdvbv5/dvb-sat.c         | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
lib/include/libdvbv5/dvb-sat.h +1 -1
index d80a619..c80545c 100644
@@ -84,7 +84,7 @@ struct dvb_sat_lnb {
 struct dvb_v5_fe_parms;
 
 #ifdef __cplusplus
-extern "C"
+extern "C" {
 #endif
 
 /* From libsat.c */
lib/libdvbv5/dvb-fe-priv.h +0 -1
index 9194431..195c3bf 100644
@@ -65,7 +65,6 @@ struct dvb_v5_fe_parms_priv {
 	struct dvb_v5_stats		stats;
 
 	/* Satellite specific stuff */
-	const struct dvb_sat_lnb       	*lnb;
 	int				high_band;
 	unsigned			freq_offset;
 };
lib/libdvbv5/dvb-sat.c +1 -1
index 8befe28..e8df06b 100644
@@ -356,7 +356,7 @@ static int dvbsat_diseqc_set_input(struct dvb_v5_fe_parms_priv *parms,
 int dvb_sat_set_parms(struct dvb_v5_fe_parms *p)
 {
 	struct dvb_v5_fe_parms_priv *parms = (void *)p;
-	const struct dvb_sat_lnb *lnb = parms->lnb;
+	const struct dvb_sat_lnb *lnb = p->lnb;
 	enum dvb_sat_polarization pol;
 	dvb_fe_retrieve_parm(&parms->p, DTV_POLARIZATION, &pol);
 	uint32_t freq;
Signature · 1 line
1.9.1