Skip to content

Commit

Permalink
2.8.3 (python_v0.7.3)
Browse files Browse the repository at this point in the history
Issue #202 Segmentation fault in python when explicit item is wrong
  • Loading branch information
dsalantic committed Apr 5, 2022
1 parent e3bfcdd commit ea41134
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
5 changes: 4 additions & 1 deletion HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,7 @@ Issue #181 Add missing Single Antenna (SA) element in Data Item I021/008 for CAT
Issue #182 convert timestamp to double, improves precision

2.8.2 (python_v0.7.2)
Issue #183 Potential Heap-based Buffer Overflow
Issue #183 Potential Heap-based Buffer Overflow

2.8.3 (python_v0.7.3)
Issue #202 Segmentation fault in python when explicit item is wrong
2 changes: 1 addition & 1 deletion asterix/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.2'
__version__ = '0.7.3'
2 changes: 1 addition & 1 deletion src/asterix/DataItemFormatCompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void DataItemFormatCompound::insertToDict(PyObject* p, unsigned char* pData, lon
it2++;
if (it2 == m_lSubItems.end())
{
Tracer::Error("Missing secondary subfields of Compund");
Tracer::Error("Missing secondary subfields of Compound");
return;
}

Expand Down
16 changes: 14 additions & 2 deletions src/asterix/DataItemFormatExplicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ bool DataItemFormatExplicit::getText(std::string &strResult, std::string &strHea
int bodyLength = 0;
bool ret = false;

if (nLength <= 1) {
Tracer::Error("Not enough data in Explicit. There is %d byte.", nLength);
return false;
}

pData++; // skip explicit length byte (it is already in nLength)

// calculate the size of all sub items
Expand Down Expand Up @@ -210,6 +215,12 @@ PyObject* DataItemFormatExplicit::getObject(unsigned char* pData, long nLength,
std::list<DataItemFormat *>::iterator it;
int bodyLength = 0;

if (nLength <= 1) {
char errorText[256];
snprintf(errorText, 255, "Not enough data in Explicit. There is %d byte.", nLength);
return Py_BuildValue("s", errorText);
}

pData++; // skip explicit length byte (it is already in nLength)

// calculate the size of all sub items
Expand All @@ -222,8 +233,9 @@ PyObject* DataItemFormatExplicit::getObject(unsigned char* pData, long nLength,

// full length must be multiple of body length
if (bodyLength == 0 || nFullLength % bodyLength != 0) {
//TODO Tracer::Error("Wrong data length in Explicit. Needed=%d and there is %d bytes.", bodyLength, nFullLength);
return NULL;
char errorText[256];
snprintf(errorText, 255, "Wrong data length in Explicit. Needed=%d and there is %d bytes.", bodyLength, nFullLength);
return Py_BuildValue("s", errorText);
}

if (nFullLength == bodyLength) {
Expand Down
12 changes: 8 additions & 4 deletions src/asterix/DataItemFormatRepetitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,21 @@ PyObject* DataItemFormatRepetitive::getObject(unsigned char* pData, long nLength
DataItemFormatFixed* pFixed = m_lSubItems.size() ? (DataItemFormatFixed*)m_lSubItems.front() : NULL;
if (!pFixed)
{
// TODO Tracer::Error("Wrong format of repetitive item");
return NULL;
PyObject* p1 = Py_BuildValue("s", "Wrong format of Repetitive item");
PyList_Append(p, p1);
Py_DECREF(p1);
return p;
}

int fixedLength = pFixed->getLength(pData);
unsigned char nRepetition = *pData;

if (1+nRepetition*fixedLength != nLength)
{
//TODO Tracer::Error("Wrong length in Repetitive");
return NULL;
PyObject* p1 = Py_BuildValue("s", "Wrong length in Repetitive item");
PyList_Append(p, p1);
Py_DECREF(p1);
return p;
}

pData++;
Expand Down
3 changes: 3 additions & 0 deletions src/asterix/DataRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ PyObject* DataRecord::getData(int verbose)
if (di)
{
PyObject* v1 = di->getData(verbose);
if (v1 == NULL) {
v1 = Py_BuildValue("s", "Error");
}
char tmp[20];
snprintf(tmp, 20, "I%s", di->m_pDescription->m_strID.c_str());
PyObject* k1 = Py_BuildValue("s", tmp);
Expand Down
4 changes: 2 additions & 2 deletions src/main/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef VERSION_H
#define VERSION_H

#define _VERSION 2.8.2
#define _VERSION_STR "2.8.2"
#define _VERSION 2.8.3
#define _VERSION_STR "2.8.3"

#endif

0 comments on commit ea41134

Please sign in to comment.