summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Lorenz <jlorenz@de.adit-jv.com>2018-02-05 17:15:41 +0100
committerJens Lorenz <jlorenz@de.adit-jv.com>2018-02-05 17:15:41 +0100
commitc60d46d3f97dcf185f1716388eaa3907c2e545e5 (patch)
tree87f4899e91d1b9a1ed1b6e9103034097c54d4afa
parentd501459e08a7b20164ad4711bd999377f79ca8a7 (diff)
downloadaudiomanager-c60d46d3f97dcf185f1716388eaa3907c2e545e5.tar.gz
AMUtil: Fixes infinite loop in dlt wrapper for out of range values of enumerations.
Signed-off-by: Kapildev Patel <kpatel@jp.adit-jv.com>
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h367
1 files changed, 183 insertions, 184 deletions
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index 8c5678e..25a62c7 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -29,68 +29,68 @@
#include "audiomanagertypes.h"
#ifdef WITH_DLT
- #include <dlt.h>
+ #include <dlt.h>
#else
- #include <stdint.h>
- #include <sstream>
-
- #define DLT_USER_BUF_MAX_SIZE 2048
-
- /**
- * This structure is used for every context used in an application.
- */
- typedef struct
- {
- char contextID[4]; /**< context id */
- int32_t log_level_pos; /**< offset in user-application context field */
- int32_t log_level_user; /** any message above this log level is not logged */
- } DltContext;
-
- /**
- * Definition of DLT trace status
- */
- typedef enum
- {
- DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
- DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
- DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
- } DltTraceStatusType;
-
- /**
- * This structure is used for context data used in an application.
- */
- typedef struct
- {
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char* context_description; /**< description of context */
- } DltContextData;
-
- /**
- * Definitions of DLT log level
- */
- typedef enum
- {
- DLT_LOG_DEFAULT = -1, /**< Default log level */
- DLT_LOG_OFF = 0x00, /**< Log level off */
- DLT_LOG_FATAL = 0x01, /**< fatal system error */
- DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
- DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
- DLT_LOG_INFO = 0x04, /**< informational */
- DLT_LOG_DEBUG = 0x05, /**< debug */
- DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
- } DltLogLevelType;
-
- #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
- #define DLT_DECLARE_CONTEXT(CONTEXT) \
- DltContext CONTEXT;
-
- #define DLT_IMPORT_CONTEXT(CONTEXT) \
- extern DltContext CONTEXT;
+ #include <stdint.h>
+ #include <sstream>
+
+ #define DLT_USER_BUF_MAX_SIZE 2048
+
+ /**
+ * This structure is used for every context used in an application.
+ */
+ typedef struct
+ {
+ char contextID[4]; /**< context id */
+ int32_t log_level_pos; /**< offset in user-application context field */
+ int32_t log_level_user; /** any message above this log level is not logged */
+ } DltContext;
+
+ /**
+ * Definition of DLT trace status
+ */
+ typedef enum
+ {
+ DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
+ DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
+ DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
+ } DltTraceStatusType;
+
+ /**
+ * This structure is used for context data used in an application.
+ */
+ typedef struct
+ {
+ DltContext *handle; /**< pointer to DltContext */
+ std::stringstream buffer; /**< buffer for building log message*/
+ int32_t log_level; /**< log level */
+ int32_t trace_status; /**< trace status */
+ int32_t args_num; /**< number of arguments for extended header*/
+ uint8_t mcnt; /**< message counter */
+ char* context_description; /**< description of context */
+ } DltContextData;
+
+ /**
+ * Definitions of DLT log level
+ */
+ typedef enum
+ {
+ DLT_LOG_DEFAULT = -1, /**< Default log level */
+ DLT_LOG_OFF = 0x00, /**< Log level off */
+ DLT_LOG_FATAL = 0x01, /**< fatal system error */
+ DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
+ DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
+ DLT_LOG_INFO = 0x04, /**< informational */
+ DLT_LOG_DEBUG = 0x05, /**< debug */
+ DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
+ } DltLogLevelType;
+
+ #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
+ #define DLT_DECLARE_CONTEXT(CONTEXT) \
+ DltContext CONTEXT;
+
+ #define DLT_IMPORT_CONTEXT(CONTEXT) \
+ extern DltContext CONTEXT;
#endif // WITH_DLT
@@ -107,56 +107,55 @@ class CAmDltWrapper
{
public:
- /**
- * This structure is used for context data used in an application.
- */
- typedef struct
- {
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char* context_description; /**< description of context */
- } NoDltContextData;
-
- /*
- * The eunum gives the logtype
- */
- enum logDestination
- {
- DAEMON=0, //!< logging with the DLT daemon
- COMMAND_LINE=1, //!< logging with commandline
- FILE_OUT =2 //!< logging into a file
- };
-
- /**
- * Instanciate the Dlt Wrapper
- * @param appid The AppID
- * @param description A description of the Application
- * @param debugEnabled if set to true, debug outputs will be generated, default = true
- * @param logDest the destination, the log should be written
- * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT
- * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false
- */
- static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false);
+ /**
+ * This structure is used for context data used in an application.
+ */
+ typedef struct
+ {
+ DltContext *handle; /**< pointer to DltContext */
+ std::stringstream buffer; /**< buffer for building log message*/
+ int32_t log_level; /**< log level */
+ int32_t trace_status; /**< trace status */
+ int32_t args_num; /**< number of arguments for extended header*/
+ uint8_t mcnt; /**< message counter */
+ char* context_description; /**< description of context */
+ } NoDltContextData;
+
+ /*
+ * The eunum gives the logtype
+ */
+ enum logDestination
+ {
+ DAEMON=0, //!< logging with the DLT daemon
+ COMMAND_LINE=1, //!< logging with commandline
+ FILE_OUT =2 //!< logging into a file
+ };
+
+ /**
+ * Instanciate the Dlt Wrapper
+ * @param appid The AppID
+ * @param description A description of the Application
+ * @param debugEnabled if set to true, debug outputs will be generated, default = true
+ * @param logDest the destination, the log should be written
+ * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT
+ * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false
+ */
+ static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false);
/**
* get the Wrapper Instance
*/
static CAmDltWrapper* instance();
-
- /**
- * register a context
- */
+
+ /**
+ * register a context
+ */
void registerContext(DltContext& handle, const char *contextid, const char * description);
void registerContext(DltContext& handle, const char *contextid, const char * description, const DltLogLevelType level, const DltTraceStatusType status);
void unregisterContext(DltContext& handle);
bool getEnabled();
~CAmDltWrapper();
-
-
+
bool init(DltLogLevelType loglevel, DltContext* context = NULL);
bool checkLogLevel(DltLogLevelType logLevel)
{
@@ -186,147 +185,147 @@ public:
void append(const std::vector<uint8_t> & data);
template<class T> void appendNoDLT(T value)
- {
- mNoDltContextData.buffer << value <<" ";
- }
+ {
+ mNoDltContextData.buffer << value <<" ";
+ }
// specialization for const char*
template<typename T = const char*> void append(const char* value)
{
- #ifdef WITH_DLT
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_string(&mDltContextData, value);
- }
- else
- {
- mNoDltContextData.buffer << std::string(value);
- }
- #else
- mNoDltContextData.buffer << std::string(value);
- #endif //WITH_DLT
-
- }
-
+ #ifdef WITH_DLT
+ if (mlogDestination == logDestination::DAEMON)
+ {
+ dlt_user_log_write_string(&mDltContextData, value);
+ }
+ else
+ {
+ mNoDltContextData.buffer << std::string(value);
+ }
+ #else
+ mNoDltContextData.buffer << std::string(value);
+ #endif //WITH_DLT
+
+ }
+
private:
- static const std::vector<const char*> mStr_error;
- static const std::vector<const char*> mStr_sourceState;
- static const std::vector<const char*> mStr_MuteState;
- static const std::vector<const char*> mStr_DomainState;
- static const std::vector<const char*> mStr_ConnectionState;
- static const std::vector<const char*> mStr_Availability;
- static const std::vector<const char*> mStr_Interrupt;
- static const std::vector<const char*> mStr_Handle;
- static const std::vector<const char*> mStr_NotificationStatus;
+ static const std::vector<const char*> mStr_error;
+ static const std::vector<const char*> mStr_sourceState;
+ static const std::vector<const char*> mStr_MuteState;
+ static const std::vector<const char*> mStr_DomainState;
+ static const std::vector<const char*> mStr_ConnectionState;
+ static const std::vector<const char*> mStr_Availability;
+ static const std::vector<const char*> mStr_Interrupt;
+ static const std::vector<const char*> mStr_Handle;
+ static const std::vector<const char*> mStr_NotificationStatus;
public:
// specialization for const am_Error_e
template<typename T = const am_Error_e> void append(const am_Error_e value)
{
- if ((int)value >=mStr_error.size())
+ if (static_cast<std::size_t>(value) >= mStr_error.size())
{
- append("value for am_Error_e out of bounds!");
- append(value);
- return;
+ append("value for am_Error_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_error[value]);
+ append(mStr_error[value]);
}
// specialization for const am_Error_e
template<typename T = const am_SourceState_e> void append(const am_SourceState_e value)
{
- if ((int)value >=(mStr_sourceState.size()))
+ if (static_cast<std::size_t>(value) >= mStr_sourceState.size())
{
- append("value for am_SourceState_e out of bounds!");
- append(value);
- return;
+ append("value for am_SourceState_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_sourceState[value]);
+ append(mStr_sourceState[value]);
}
template<typename T = const am_MuteState_e> void append(const am_MuteState_e value)
{
- if ((int)value >=mStr_MuteState.size())
+ if (static_cast<std::size_t>(value) >= mStr_MuteState.size())
{
- append("value for am_MuteState_e out of bounds!");
- append(value);
- return;
+ append("value for am_MuteState_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_MuteState[value]);
+ append(mStr_MuteState[value]);
}
template<typename T = const am_DomainState_e> void append(const am_DomainState_e value)
{
- if ((int)value >= mStr_DomainState.size())
+ if (static_cast<std::size_t>(value) >= mStr_DomainState.size())
{
- append("value for am_DomainState_e out of bounds!");
- append(value);
- return;
+ append("value for am_DomainState_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_DomainState[value]);
+ append(mStr_DomainState[value]);
}
template<typename T = const am_ConnectionState_e> void append(const am_ConnectionState_e value)
{
- if ((int)value >=mStr_ConnectionState.size())
+ if (static_cast<std::size_t>(value) >= mStr_ConnectionState.size())
{
- append("value for am_ConnectionState_e out of bounds!");
- append(value);
- return;
+ append("value for am_ConnectionState_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_ConnectionState[value]);
+ append(mStr_ConnectionState[value]);
}
template<typename T = const am_Availability_e> void append(const am_Availability_e value)
{
- if ((int)value >= mStr_Availability.size())
+ if (static_cast<std::size_t>(value) >= mStr_Availability.size())
{
- append("value for am_Availability_e out of bounds!");
- append(value);
- return;
+ append("value for am_Availability_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_Availability[value]);
+ append(mStr_Availability[value]);
}
template<typename T = const am_InterruptState_e> void append(const am_InterruptState_e value)
{
- if ((int)value >=mStr_Interrupt.size())
+ if (static_cast<std::size_t>(value) >= mStr_Interrupt.size())
{
- append("value for am_InterruptState_e out of bounds!");
- append(value);
- return;
+ append("value for am_InterruptState_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_Interrupt[value]);
+ append(mStr_Interrupt[value]);
}
template<typename T = const am_Handle_e> void append(const am_Handle_e value)
{
- if ((int)value >=mStr_Handle.size())
+ if (static_cast<std::size_t>(value) >= mStr_Handle.size())
{
- append("value for am_Handle_e out of bounds!");
- append(value);
- return;
+ append("value for am_Handle_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_Handle[value]);
+ append(mStr_Handle[value]);
}
template<typename T = const am_Handle_s> void append(const am_Handle_s value)
{
- append (value.handleType);
- append (value.handle);
+ append (value.handleType);
+ append (value.handle);
}
template<typename T = const am_NotificationStatus_e> void append(const am_NotificationStatus_e value)
{
- if ((int)value >=mStr_NotificationStatus.size())
+ if (static_cast<std::size_t>(value) >= mStr_NotificationStatus.size())
{
- append("value for am_NotificationStatus_e out of bounds!");
- append(value);
- return;
+ append("value for am_NotificationStatus_e out of bounds!");
+ append(static_cast<uint16_t>(value));
+ return;
}
- append(mStr_NotificationStatus[value]);
+ append(mStr_NotificationStatus[value]);
}
// Template to print unknown pointer types with their address
@@ -354,9 +353,9 @@ public:
}
private:
- /**
- * private contructor
- */
+ /**
+ * private contructor
+ */
CAmDltWrapper(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); //is private because of singleton pattern
bool initNoDlt(DltLogLevelType loglevel, DltContext* context);
std::string now();
@@ -364,7 +363,7 @@ private:
DltContextData mDltContextData; //!< contextdata
NoDltContextData mNoDltContextData; //!<contextdata for std out logging
std::map<DltContext*,std::string> mMapContext; //!< a Map for all registered context
- bool mDebugEnabled; //!< debug Enabled or not
+ bool mDebugEnabled; //!< debug Enabled or not
logDestination mlogDestination; //!< The log destination
std::ofstream mFilename; //!< Filename for logging
bool mOnlyError; //!< Only if Log Level is above Error
@@ -385,14 +384,14 @@ template<typename T, typename... TArgs>
void log(DltContext* const context, DltLogLevelType loglevel, T value, TArgs... args)
{
CAmDltWrapper* inst(CAmDltWrapper::instance());
- if (!inst->getEnabled())
+ if (!inst->getEnabled())
{
- return;
- }
+ return;
+ }
if (!inst->init(loglevel, context))
{
- return;
- }
+ return;
+ }
inst->append(value);
inst->append(args...);
inst->send();