summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2006-02-18 10:42:55 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2006-02-18 10:42:55 +0100
commit5ed4504ce0fc510d29492bcf480113f3e01f069e (patch)
tree8c6cf0c794ebd5aecf23a6cbbd6b4b18e6632b20
parentafebd4b2fba946cbac1309bf282a88d1cc179f62 (diff)
downloadvdr-5ed4504ce0fc510d29492bcf480113f3e01f069e.tar.gz
vdr-5ed4504ce0fc510d29492bcf480113f3e01f069e.tar.bz2
Changed offset and size handling in 'libsi' from 'unsigned' to 'signed', so that overflows can be better detected
-rw-r--r--HISTORY4
-rw-r--r--libsi/descriptor.c34
-rw-r--r--libsi/section.c30
-rw-r--r--libsi/si.c6
-rw-r--r--libsi/si.h10
-rw-r--r--libsi/util.c14
-rw-r--r--libsi/util.h34
7 files changed, 67 insertions, 65 deletions
diff --git a/HISTORY b/HISTORY
index 2a7c1ba0..5a605183 100644
--- a/HISTORY
+++ b/HISTORY
@@ -4317,7 +4317,7 @@ Video Disk Recorder Revision History
- Added cSkin::GetTextAreaWidth() and cSkin::GetTextAreaFont(), so that a plugin
that wants to do special text formatting can do so (thanks to Alexander Rieger).
-2006-02-17: Version 1.3.43
+2006-02-18: Version 1.3.43
- Removed an unnecessary toFile->SetReadAhead() from cutter.c (thanks to Artur
Skawina).
@@ -4332,3 +4332,5 @@ Video Disk Recorder Revision History
- cMenuText now uses the given font (thanks to Rolf Ahrenberg).
- The ST:TNG skin now uses the fixed font if requested when displaying texts.
- Fixed some typos in the CONTRIBUTORS file (thanks to Frank Krömmelbein).
+- Changed offset and size handling in 'libsi' from 'unsigned' to 'signed', so that
+ overflows can be better detected (thanks to Marcel Wiesweg).
diff --git a/libsi/descriptor.c b/libsi/descriptor.c
index cc3a0169..d27da2b7 100644
--- a/libsi/descriptor.c
+++ b/libsi/descriptor.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: descriptor.c 1.15 2005/09/03 15:16:49 kls Exp $
+ * $Id: descriptor.c 1.16 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -16,7 +16,7 @@
namespace SI {
void ShortEventDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
const descr_short_event *s;
data.setPointerAndOffset<const descr_short_event>(s, offset);
languageCode[0]=s->lang_code1;
@@ -38,7 +38,7 @@ int ExtendedEventDescriptor::getLastDescriptorNumber() {
}
void ExtendedEventDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_extended_event>(s, offset);
languageCode[0]=s->lang_code1;
languageCode[1]=s->lang_code2;
@@ -51,7 +51,7 @@ void ExtendedEventDescriptor::Parse() {
}
void ExtendedEventDescriptor::Item::Parse() {
- unsigned int offset=0;
+ int offset=0;
const item_extended_event *first;
data.setPointerAndOffset<const item_extended_event>(first, offset);
itemDescription.setDataAndOffset(data+offset, first->item_description_length, offset);
@@ -327,7 +327,7 @@ int CaDescriptor::getCaPid() const {
}
void CaDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_ca>(s, offset);
privateData.assign(data.getData(offset), getLength()-offset);
}
@@ -477,7 +477,7 @@ int ServiceDescriptor::getServiceType() const {
}
void ServiceDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_service>(s, offset);
providerName.setDataAndOffset(data+offset, s->provider_name_length, offset);
const descr_service_mid *mid;
@@ -526,7 +526,7 @@ int ComponentDescriptor::getComponentTag() const {
}
void ComponentDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_component>(s, offset);
languageCode[0]=s->lang_code1;
languageCode[1]=s->lang_code2;
@@ -580,7 +580,7 @@ int FrequencyListDescriptor::getCodingType() const {
}
void FrequencyListDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_frequency_list>(s, offset);
frequencies.setData(data+offset, getLength()-offset);
}
@@ -594,7 +594,7 @@ void MultilingualNameDescriptor::Parse() {
}
void MultilingualNameDescriptor::Name::Parse() {
- unsigned int offset=0;
+ int offset=0;
const entry_multilingual_name *s;
data.setPointerAndOffset<const entry_multilingual_name>(s, offset);
languageCode[0]=s->lang_code1;
@@ -609,7 +609,7 @@ int MultilingualComponentDescriptor::getComponentTag() const {
}
void MultilingualComponentDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_multilingual_component>(s, offset);
nameLoop.setData(data+sizeof(descr_multilingual_component), getLength()-sizeof(descr_multilingual_component));
}
@@ -619,7 +619,7 @@ void MultilingualServiceNameDescriptor::Parse() {
}
void MultilingualServiceNameDescriptor::Name::Parse() {
- unsigned int offset=0;
+ int offset=0;
const entry_multilingual_name *s;
data.setPointerAndOffset<const entry_multilingual_name>(s, offset);
languageCode[0]=s->lang_code1;
@@ -633,7 +633,7 @@ void MultilingualServiceNameDescriptor::Name::Parse() {
}
void LinkageDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_linkage>(s, offset);
privateData.assign(data.getData(offset), getLength()-offset);
}
@@ -682,7 +682,7 @@ AudioType ISO639LanguageDescriptor::Language::getAudioType() {
}
void PDCDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_pdc>(s, offset);
}
@@ -731,7 +731,7 @@ int MHP_ApplicationDescriptor::getApplicationPriority() const {
}
void MHP_ApplicationDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
const descr_application *dapp;
data.setPointerAndOffset<const descr_application>(dapp, offset);
profileLoop.setDataAndOffset(data+offset, dapp->application_profiles_length, offset);
@@ -790,7 +790,7 @@ int MHP_TransportProtocolDescriptor::getComponentTag() const {
}
void MHP_TransportProtocolDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const descr_transport_protocol>(s, offset);
if (getProtocolId() == ObjectCarousel) {
const transport_via_oc *oc;
@@ -821,7 +821,7 @@ void MHP_DVBJApplicationDescriptor::ApplicationEntry::Parse() {
}
void MHP_DVBJApplicationLocationDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
const descr_dvbj_application_location *first;
data.setPointerAndOffset<const descr_dvbj_application_location>(first, offset);
baseDirectory.setDataAndOffset(data+offset, first->base_directory_length, offset);
@@ -836,7 +836,7 @@ int MHP_ApplicationIconsDescriptor::getIconFlags() const {
}
void MHP_ApplicationIconsDescriptor::Parse() {
- unsigned int offset=0;
+ int offset=0;
const descr_application_icons_descriptor *first;
data.setPointerAndOffset<const descr_application_icons_descriptor>(first, offset);
iconLocator.setDataAndOffset(data+offset, first->icon_locator_length, offset);
diff --git a/libsi/section.c b/libsi/section.c
index 2cac809d..68af9918 100644
--- a/libsi/section.c
+++ b/libsi/section.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: section.c 1.3 2004/02/20 13:44:59 kls Exp $
+ * $Id: section.c 1.4 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -18,7 +18,7 @@ namespace SI {
/*********************** PAT ***********************/
void PAT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const pat>(s, offset);
associationLoop.setData(data+offset, getLength()-offset-4);
}
@@ -48,7 +48,7 @@ void CAT::Parse() {
/*********************** PMT ***********************/
void PMT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const pmt>(s, offset);
commonDescriptors.setDataAndOffset(data+offset, HILO(s->program_info_length), offset);
streamLoop.setData(data+offset, getLength()-offset-4);
@@ -71,7 +71,7 @@ int PMT::Stream::getStreamType() const {
}
void PMT::Stream::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const pmt_info>(s, offset);
streamDescriptors.setData(data+offset, HILO(s->ES_info_length));
}
@@ -79,7 +79,7 @@ void PMT::Stream::Parse() {
/*********************** TSDT ***********************/
void TSDT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const tsdt>(s, offset);
transportStreamDescriptors.setDataAndOffset(data+offset, getLength()-offset-4, offset);
}
@@ -91,7 +91,7 @@ int NIT::getNetworkId() const {
}
void NIT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const nit>(s, offset);
commonDescriptors.setDataAndOffset(data+offset, HILO(s->network_descriptor_length), offset);
const nit_mid *mid;
@@ -108,7 +108,7 @@ int NIT::TransportStream::getOriginalNetworkId() const {
}
void NIT::TransportStream::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const ni_ts>(s, offset);
transportStreamDescriptors.setData(data+offset, HILO(s->transport_descriptors_length));
}
@@ -116,7 +116,7 @@ void NIT::TransportStream::Parse() {
/*********************** SDT ***********************/
void SDT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const sdt>(s, offset);
serviceLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC
}
@@ -150,7 +150,7 @@ int SDT::Service::getFreeCaMode() const {
}
void SDT::Service::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const sdt_descr>(s, offset);
serviceDescriptors.setData(data+offset, HILO(s->descriptors_loop_length));
}
@@ -188,7 +188,7 @@ bool EIT::isActualTS() const {
}
void EIT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const eit>(s, offset);
//printf("%d %d %d %d %d\n", getServiceId(), getTransportStreamId(), getOriginalNetworkId(), isPresentFollowing(), isActualTS());
eventLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC
@@ -243,7 +243,7 @@ int EIT::Event::getFreeCaMode() const {
}
void EIT::Event::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const eit_event>(s, offset);
//printf("%d %d %d\n", getStartTime(), getDuration(), getRunningStatus());
eventDescriptors.setData(data+offset, HILO(s->descriptors_loop_length));
@@ -266,7 +266,7 @@ time_t TOT::getTime() const {
}
void TOT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const tot>(s, offset);
descriptorLoop.setData(data+offset, getLength()-offset-4);
}
@@ -274,7 +274,7 @@ void TOT::Parse() {
/*********************** RST ***********************/
void RST::Parse() {
- unsigned int offset=0;
+ int offset=0;
const rst *s;
data.setPointerAndOffset<const rst>(s, offset);
infoLoop.setData(data+offset, getLength()-offset);
@@ -315,7 +315,7 @@ int AIT::getAITVersion() const {
}
void AIT::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const ait>(first, offset);
commonDescriptors.setDataAndOffset(data+offset, HILO(first->common_descriptors_length), offset);
const ait_mid *mid;
@@ -336,7 +336,7 @@ int AIT::Application::getControlCode() const {
}
void AIT::Application::Parse() {
- unsigned int offset=0;
+ int offset=0;
data.setPointerAndOffset<const ait_app>(s, offset);
applicationDescriptors.setData(data+offset, HILO(s->application_descriptors_length));
}
diff --git a/libsi/si.c b/libsi/si.c
index 90d40303..bbd3f1af 100644
--- a/libsi/si.c
+++ b/libsi/si.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: si.c 1.14 2005/05/28 14:11:16 kls Exp $
+ * $Id: si.c 1.15 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -22,7 +22,7 @@ Object::Object() {
Object::Object(CharArray &d) : data(d) {
}
-void Object::setData(const unsigned char*d, unsigned int size, bool doCopy) {
+void Object::setData(const unsigned char*d, int size, bool doCopy) {
data.assign(d, size, doCopy);
}
@@ -30,7 +30,7 @@ void Object::setData(CharArray &d) {
data=d;
}
-bool Object::checkSize(unsigned int offset) {
+bool Object::checkSize(int offset) {
return data.checkSize(offset);
}
diff --git a/libsi/si.h b/libsi/si.h
index 3836b2fb..c8910ffb 100644
--- a/libsi/si.h
+++ b/libsi/si.h
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: si.h 1.12 2005/09/03 15:19:00 kls Exp $
+ * $Id: si.h 1.13 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -184,7 +184,7 @@ public:
Object();
Object(CharArray &d);
//can only be called once since data is immutable
- void setData(const unsigned char*data, unsigned int size, bool doCopy=true);
+ void setData(const unsigned char*data, int size, bool doCopy=true);
CharArray getData() { return data; }
//returns the valid flag which indicates if data is all right or errors have been encountered
bool isValid() { return data.isValid(); }
@@ -196,7 +196,7 @@ protected:
void setData(CharArray &d);
//returns whether the given offset fits within the limits of the actual data
//The valid flag will be set accordingly
- bool checkSize(unsigned int offset);
+ bool checkSize(int offset);
};
class Section : public Object {
@@ -242,7 +242,7 @@ public:
//never forget to call this
void setData(CharArray d, int l) { Object::setData(d); checkSize(l); length=l; }
//convenience method
- void setDataAndOffset(CharArray d, int l, unsigned int &offset) { Object::setData(d); checkSize(l); length=l; offset+=l; }
+ void setDataAndOffset(CharArray d, int l, int &offset) { Object::setData(d); checkSize(l); length=l; offset+=l; }
virtual int getLength() { return length; }
private:
int length;
@@ -384,7 +384,7 @@ typedef uint64_t SixtyFourBit;
template <typename T> class TypeLoop : public Loop {
public:
int getCount() { return getLength()/sizeof(T); }
- T operator[](const unsigned int index) const
+ T operator[](const int index) const
{
switch (sizeof(T)) {
case 1:
diff --git a/libsi/util.c b/libsi/util.c
index 34657948..bbdf86b2 100644
--- a/libsi/util.c
+++ b/libsi/util.c
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: util.c 1.5 2005/05/28 14:15:29 kls Exp $
+ * $Id: util.c 1.6 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -47,7 +47,7 @@ CharArray& CharArray::operator=(const CharArray &f) {
return *this;
}
-void CharArray::assign(const unsigned char*data, unsigned int size, bool doCopy) {
+void CharArray::assign(const unsigned char*data, int size, bool doCopy) {
//immutable
if (!data_)
data_= doCopy ? (Data*)new DataOwnData() : (Data*)new DataForeignData();
@@ -76,13 +76,13 @@ bool CharArray::operator==(const CharArray &other) const {
return false;
//do _not_ use strcmp! Data is not necessarily null-terminated.
- for (unsigned int i=0;i<data_->size;i++)
+ for (int i=0;i<data_->size;i++)
if (data_->data[i] != other.data_->data[i])
return false;
return true;
}
-CharArray CharArray::operator+(const unsigned int offset) const {
+CharArray CharArray::operator+(const int offset) const {
CharArray f(*this);
f.off+=offset;
return f;
@@ -117,7 +117,7 @@ CharArray::DataOwnData::~DataOwnData() {
Delete();
}
-void CharArray::DataOwnData::assign(const unsigned char*d, unsigned int s) {
+void CharArray::DataOwnData::assign(const unsigned char*d, int s) {
Delete();
size=s;
unsigned char *newdata=new unsigned char[size];
@@ -133,7 +133,7 @@ CharArray::DataForeignData::~DataForeignData() {
Delete();
}
-void CharArray::DataForeignData::assign(const unsigned char*d, unsigned int s) {
+void CharArray::DataForeignData::assign(const unsigned char*d, int s) {
size=s;
data=d;
}
@@ -143,7 +143,7 @@ void CharArray::DataForeignData::Delete() {
}
/*
-void CharArray::Data::assign(unsigned int s) {
+void CharArray::Data::assign(int s) {
if (data)
delete[] data;
size=s;
diff --git a/libsi/util.h b/libsi/util.h
index da188ad4..91a4c32a 100644
--- a/libsi/util.h
+++ b/libsi/util.h
@@ -6,7 +6,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * $Id: util.h 1.5 2004/10/23 14:22:40 kls Exp $
+ * $Id: util.h 1.6 2006/02/18 10:38:20 kls Exp $
* *
***************************************************************************/
@@ -37,14 +37,14 @@ public:
~CharArray();
//can be called exactly once
- void assign(const unsigned char*data, unsigned int size, bool doCopy=true);
+ void assign(const unsigned char*data, int size, bool doCopy=true);
//compares to a null-terminated string
bool operator==(const char *string) const;
//compares to another CharArray (data not necessarily null-terminated)
bool operator==(const CharArray &other) const;
//returns another CharArray with its offset incremented by offset
- CharArray operator+(const unsigned int offset) const;
+ CharArray operator+(const int offset) const;
//access and convenience methods
const unsigned char* getData() const { return data_->data+off; }
@@ -52,28 +52,28 @@ public:
template <typename T> const T* getData() const { return (T*)(data_->data+off); }
template <typename T> const T* getData(int offset) const { return (T*)(data_->data+offset+off); }
//sets p to point to data+offset, increments offset
- template <typename T> void setPointerAndOffset(const T* &p, unsigned int &offset) const { p=(T*)getData(offset); offset+=sizeof(T); }
- unsigned char operator[](const unsigned int index) const { return data_->data ? data_->data[off+index] : 0; }
+ template <typename T> void setPointerAndOffset(const T* &p, int &offset) const { p=(T*)getData(offset); offset+=sizeof(T); }
+ unsigned char operator[](const int index) const { return data_->data ? data_->data[off+index] : 0; }
int getLength() const { return data_->size; }
- u_int16_t TwoBytes(const unsigned int index) const { return data_->data ? data_->TwoBytes(off+index) : 0; }
- u_int32_t FourBytes(const unsigned int index) const { return data_->data ? data_->FourBytes(off+index) : 0; }
+ u_int16_t TwoBytes(const int index) const { return data_->data ? data_->TwoBytes(off+index) : 0; }
+ u_int32_t FourBytes(const int index) const { return data_->data ? data_->FourBytes(off+index) : 0; }
bool isValid() const { return data_->valid; }
- bool checkSize(unsigned int offset) { return (data_->valid && (data_->valid=(off+offset < data_->size))); }
+ bool checkSize(int offset) { return (data_->valid && offset>=0 && (data_->valid=(off+offset < data_->size))); }
- void addOffset(unsigned int offset) { off+=offset; }
+ void addOffset(int offset) { off+=offset; }
private:
class Data {
public:
Data();
virtual ~Data();
- virtual void assign(const unsigned char*data, unsigned int size) = 0;
+ virtual void assign(const unsigned char*data, int size) = 0;
virtual void Delete() = 0;
- u_int16_t TwoBytes(const unsigned int index) const
+ u_int16_t TwoBytes(const int index) const
{ return (data[index] << 8) | data[index+1]; }
- u_int32_t FourBytes(const unsigned int index) const
+ u_int32_t FourBytes(const int index) const
{ return (data[index] << 24) | (data[index+1] << 16) | (data[index+2] << 8) | data[index+3]; }
/*#ifdef CHARARRAY_THREADSAFE
void Lock();
@@ -83,11 +83,11 @@ private:
void Unlock() {}
#endif
Data(const Data& d);
- void assign(unsigned int size);
+ void assign(int size);
*/
const unsigned char*data;
- unsigned int size;
+ int size;
// count_ is the number of CharArray objects that point at this
// count_ must be initialized to 1 by all constructors
@@ -106,18 +106,18 @@ private:
public:
DataOwnData() {}
virtual ~DataOwnData();
- virtual void assign(const unsigned char*data, unsigned int size);
+ virtual void assign(const unsigned char*data, int size);
virtual void Delete();
};
class DataForeignData : public Data {
public:
DataForeignData() {}
virtual ~DataForeignData();
- virtual void assign(const unsigned char*data, unsigned int size);
+ virtual void assign(const unsigned char*data, int size);
virtual void Delete();
};
Data* data_;
- unsigned int off;
+ int off;
};