eitd: fix content classification bug introduced in 6eb8fa1c9e3a70a1e60465b838fe954c51e478b6

Origin commit data
------------------
Commit: c5ab2b994f
Author: martii <m4rtii@gmx.de>
Date: 2014-09-22 (Mon, 22 Sep 2014)
This commit is contained in:
martii
2014-09-22 22:24:42 +02:00
committed by [CST] Focus
parent aaad1652e8
commit eef29f8fbf
2 changed files with 52 additions and 39 deletions

View File

@@ -234,11 +234,13 @@ void SIevent::parse(Event &event)
{ {
const ContentDescriptor * d = (ContentDescriptor *) *dit; const ContentDescriptor * d = (ContentDescriptor *) *dit;
const ContentClassificationList *clist = d->getClassifications(); const ContentClassificationList *clist = d->getClassifications();
ssize_t off = classifications.reserve(clist->size() * 2); if (clist->size()) {
for (ContentClassificationConstIterator cit = clist->begin(); cit != clist->end(); ++cit) ssize_t off = classifications.reserve(clist->size() * 2);
off = classifications.set(off, for (ContentClassificationConstIterator cit = clist->begin(); cit != clist->end(); ++cit)
(*cit)->getContentNibbleLevel1() << 4 | (*cit)->getContentNibbleLevel2(), off = classifications.set(off,
(*cit)->getUserNibble1() << 4 | (*cit)->getUserNibble2()); (*cit)->getContentNibbleLevel1() << 4 | (*cit)->getContentNibbleLevel2(),
(*cit)->getUserNibble1() << 4 | (*cit)->getUserNibble2());
}
break; break;
} }
case COMPONENT_DESCRIPTOR: case COMPONENT_DESCRIPTOR:
@@ -301,21 +303,21 @@ void SIevent::parseDescriptors(const uint8_t *des, unsigned len)
while(len>=sizeof(struct descr_generic_header)) { while(len>=sizeof(struct descr_generic_header)) {
desc=(struct descr_generic_header *)des; desc=(struct descr_generic_header *)des;
/*printf("Type: %s\n", decode_descr(desc->descriptor_tag)); */ /*printf("Type: %s\n", decode_descr(desc->descriptor_tag)); */
if(desc->descriptor_tag==0x4D) if(desc->descriptor_tag==SHORT_EVENT_DESCRIPTOR)
parseShortEventDescriptor((const uint8_t *)desc, len); parseShortEventDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x4E) else if(desc->descriptor_tag==EXTENDED_EVENT_DESCRIPTOR)
parseExtendedEventDescriptor((const uint8_t *)desc, len); parseExtendedEventDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x54) else if(desc->descriptor_tag==CONTENT_DESCRIPTOR)
parseContentDescriptor((const uint8_t *)desc, len); parseContentDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x50) else if(desc->descriptor_tag==COMPONENT_DESCRIPTOR)
parseComponentDescriptor((const uint8_t *)desc, len); parseComponentDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x55) else if(desc->descriptor_tag==PARENTAL_RATING_DESCRIPTOR)
parseParentalRatingDescriptor((const uint8_t *)desc, len); parseParentalRatingDescriptor((const uint8_t *)desc, len);
else if(desc->descriptor_tag==0x4A) { else if(desc->descriptor_tag==LINKAGE_DESCRIPTOR) {
parseLinkageDescriptor((const uint8_t *)desc, len); parseLinkageDescriptor((const uint8_t *)desc, len);
} }
#if 0 #if 0
else if(desc->descriptor_tag==0x69) else if(desc->descriptor_tag==PDC_DESCRIPTOR)
parsePDCDescriptor((const char *)desc, e, len); parsePDCDescriptor((const char *)desc, e, len);
#endif #endif
if((unsigned)(desc->descriptor_length+2)>len) if((unsigned)(desc->descriptor_length+2)>len)
@@ -397,6 +399,8 @@ void SIevent::parseContentDescriptor(const uint8_t *buf, unsigned maxlen)
struct descr_generic_header *cont=(struct descr_generic_header *)buf; struct descr_generic_header *cont=(struct descr_generic_header *)buf;
if(cont->descriptor_length+sizeof(struct descr_generic_header)>maxlen) if(cont->descriptor_length+sizeof(struct descr_generic_header)>maxlen)
return; return;
if(!cont->descriptor_length)
return;
ssize_t off = classifications.reserve(cont->descriptor_length); ssize_t off = classifications.reserve(cont->descriptor_length);
classifications.set(off, buf + sizeof(struct descr_generic_header), cont->descriptor_length); classifications.set(off, buf + sizeof(struct descr_generic_header), cont->descriptor_length);
} }

View File

@@ -382,14 +382,18 @@ class SIevent
SIeventClassifications& operator = (const SIeventClassifications& c) SIeventClassifications& operator = (const SIeventClassifications& c)
{ {
if (this != &c) { if (this != &c) {
if (data) size = 0;
if (data) {
free(data); free(data);
data = NULL;
}
if (c.data) { if (c.data) {
data = (uint8_t *) malloc(c.size); data = (uint8_t *) malloc(c.size);
memcpy(data, c.data, c.size); if (data) {
} else memcpy(data, c.data, c.size);
data = NULL; size = c.size;
size = c.size; }
}
} }
return *this; return *this;
} }
@@ -397,12 +401,8 @@ class SIevent
SIeventClassifications(const SIeventClassifications& c) SIeventClassifications(const SIeventClassifications& c)
{ {
if (this != &c) { if (this != &c) {
if (c.data) { data = NULL;
data = (uint8_t *) malloc(c.size); *this = c;
memcpy(data, c.data, c.size);
} else
data = NULL;
size = c.size;
} }
} }
@@ -419,7 +419,7 @@ class SIevent
bool operator!=(const SIeventClassifications& c) const bool operator!=(const SIeventClassifications& c) const
{ {
return *this == c; return *this != c;
} }
SIeventClassifications() SIeventClassifications()
@@ -430,52 +430,61 @@ class SIevent
~SIeventClassifications() ~SIeventClassifications()
{ {
if (data) free(data); if (data)
free(data);
} }
void get(std::string &contentClassifications, std::string &userClassifications) const void get(std::string &contentClassifications, std::string &userClassifications) const
{ {
contentClassifications.clear(); contentClassifications.clear();
userClassifications.clear(); userClassifications.clear();
uint8_t *d = data; if (size) {
unsigned int z = size & ~1; uint8_t *d = data, *e = data + size;
for (unsigned int i = 0; i < z; i += 2) { uint8_t cc[size/2], uc[size/2];
contentClassifications.append(1, (char)(*d++)); for (unsigned int i = 0; d < e; i++) {
userClassifications.append(1, (char)(*d++)); cc[i] = *d++;
uc[i] = *d++;
}
contentClassifications.assign((char *) cc, size/2);
userClassifications.assign((char *) uc, size/2);
} }
} }
ssize_t reserve(unsigned int r) ssize_t reserve(unsigned int r)
{ {
size_t off = size; if (r & 1)
return -1;
if (off) { if (size) {
uint8_t * _data = (uint8_t *) realloc(data, size + r); uint8_t * _data = (uint8_t *) realloc(data, size + r);
if (!_data) if (!_data)
return -1; return -1;
data = _data; data = _data;
} else } else {
data = (uint8_t *) malloc(r); data = (uint8_t *) malloc(r);
if (!data)
return -1;
}
size_t off = size;
size += r; size += r;
return off; return off;
} }
ssize_t set(ssize_t off, uint8_t content, uint8_t user) ssize_t set(ssize_t off, uint8_t content, uint8_t user)
{ {
if (off < -1 || off + 2 >= (ssize_t) size) if (off < 0 || off + 2 > (ssize_t) size)
return -1; return -1;
data[off++] = content; data[off++] = content;
data[off++] = user; data[off++] = user;
return off; return off;
} }
ssize_t set(ssize_t off, const uint8_t *_data, size_t _size) ssize_t set(ssize_t off, const uint8_t *_data, size_t len)
{ {
if (off < -1 || off + _size >= size) if (len & 1 || off < 0 || off + len > size)
return -1; return -1;
memcpy (data + off, _data, _size); memcpy (data + off, _data, len);
size += _size; return off + len;
return size;
} }
}; };