From e107f073245c22d58a99d6efc7d2e70a13c82d38 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 8 Dec 2011 01:04:55 +0100 Subject: [PATCH] cec: removed 'retries' from cec_command, to avoid stack smashing when upgrading the libcec binary without recompiling --- include/cectypes.h | 3 --- src/lib/AdapterCommunication.cpp | 1 - src/lib/CECProcessor.cpp | 7 +++++++ src/lib/implementations/CECCommandHandler.cpp | 2 -- src/lib/implementations/CECCommandHandler.h | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/cectypes.h b/include/cectypes.h index 7bce7e2..9759fd3 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -699,7 +699,6 @@ typedef struct cec_command cec_datapacket parameters; int8_t opcode_set; int32_t transmit_timeout; - int8_t retries; #ifdef __cplusplus cec_command &operator =(const struct cec_command &command) @@ -712,7 +711,6 @@ typedef struct cec_command opcode_set = command.opcode_set; transmit_timeout = command.transmit_timeout; parameters = command.parameters; - retries = command.retries; return *this; } @@ -755,7 +753,6 @@ typedef struct cec_command opcode_set = 0; opcode = CEC_OPCODE_FEATURE_ABORT; transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT; - retries = CEC_DEFAULT_TRANSMIT_RETRIES; parameters.Clear(); }; #endif diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 2bdbb04..54077d6 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -43,7 +43,6 @@ using namespace CEC; CCECAdapterMessage::CCECAdapterMessage(const cec_command &command) { clear(); - maxTries = command.retries + 1; //set ack polarity to high when transmitting to the broadcast address //set ack polarity low when transmitting to any other address diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index e1e03b8..a3c22df 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -717,6 +717,13 @@ bool CCECProcessor::Transmit(const cec_command &data) LogOutput(data); CCECAdapterMessage *output = new CCECAdapterMessage(data); + + /* set the number of retries */ + if (data.opcode == CEC_OPCODE_NONE) + output->maxTries = 1; + else if (data.initiator != CECDEVICE_BROADCAST) + output->maxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1; + bReturn = Transmit(output); /* set to "not present" on failed ack */ diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index c58a606..5c6a52f 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -899,8 +899,6 @@ bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* = true */) { command.transmit_timeout = m_iTransmitTimeout; - if (command.retries == CEC_DEFAULT_TRANSMIT_RETRIES) - command.retries = m_iTransmitRetries; CLockObject writeLock(&m_processor->m_transmitMutex); CLockObject receiveLock(&m_receiveMutex); diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index f6f397d..e5d19ed 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -53,6 +53,7 @@ namespace CEC virtual bool HandleReceiveFailed(void); virtual bool InitHandler(void) { return true; } + virtual uint8_t GetTransmitRetries(void) const { return m_iTransmitRetries; } virtual bool TransmitPowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination); virtual bool TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination); -- 2.34.1