From ea411343786d37c96be019a7c76f850f0787b817 Mon Sep 17 00:00:00 2001 From: Damir Salantic Date: Tue, 5 Apr 2022 09:40:43 +0200 Subject: [PATCH] 2.8.3 (python_v0.7.3) Issue #202 Segmentation fault in python when explicit item is wrong --- HISTORY | 5 ++++- asterix/version.py | 2 +- src/asterix/DataItemFormatCompound.cpp | 2 +- src/asterix/DataItemFormatExplicit.cpp | 16 ++++++++++++++-- src/asterix/DataItemFormatRepetitive.cpp | 12 ++++++++---- src/asterix/DataRecord.cpp | 3 +++ src/main/version.h | 4 ++-- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/HISTORY b/HISTORY index 6d684d88..4232051b 100644 --- a/HISTORY +++ b/HISTORY @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/asterix/version.py b/asterix/version.py index fb9b668f..1ef13195 100644 --- a/asterix/version.py +++ b/asterix/version.py @@ -1 +1 @@ -__version__ = '0.7.2' +__version__ = '0.7.3' diff --git a/src/asterix/DataItemFormatCompound.cpp b/src/asterix/DataItemFormatCompound.cpp index c2eb8b9c..9f9c08e5 100644 --- a/src/asterix/DataItemFormatCompound.cpp +++ b/src/asterix/DataItemFormatCompound.cpp @@ -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; } diff --git a/src/asterix/DataItemFormatExplicit.cpp b/src/asterix/DataItemFormatExplicit.cpp index 4a22f134..93c33248 100644 --- a/src/asterix/DataItemFormatExplicit.cpp +++ b/src/asterix/DataItemFormatExplicit.cpp @@ -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 @@ -210,6 +215,12 @@ PyObject* DataItemFormatExplicit::getObject(unsigned char* pData, long nLength, std::list::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 @@ -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) { diff --git a/src/asterix/DataItemFormatRepetitive.cpp b/src/asterix/DataItemFormatRepetitive.cpp index a6bdc2e9..842d1f0f 100644 --- a/src/asterix/DataItemFormatRepetitive.cpp +++ b/src/asterix/DataItemFormatRepetitive.cpp @@ -205,8 +205,10 @@ 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); @@ -214,8 +216,10 @@ PyObject* DataItemFormatRepetitive::getObject(unsigned char* pData, long nLength 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++; diff --git a/src/asterix/DataRecord.cpp b/src/asterix/DataRecord.cpp index d7de560a..1c911e12 100644 --- a/src/asterix/DataRecord.cpp +++ b/src/asterix/DataRecord.cpp @@ -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); diff --git a/src/main/version.h b/src/main/version.h index 67bcb7f0..215e4c82 100644 --- a/src/main/version.h +++ b/src/main/version.h @@ -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