Skip to content

Commit

Permalink
fixed: osd name truncated (after v5 bump)
Browse files Browse the repository at this point in the history
closes #333
  • Loading branch information
opdenkamp committed Apr 27, 2020
1 parent 88894aa commit b6f8e69
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
12 changes: 9 additions & 3 deletions include/cectypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,16 @@ typedef struct ICECCallbacks
#endif
} ICECCallbacks;

#if CEC_LIB_VERSION_MAJOR >= 5
#define LIBCEC_OSD_NAME_SIZE (15)
#else
#define LIBCEC_OSD_NAME_SIZE (13)
#endif

struct libcec_configuration
{
uint32_t clientVersion; /*!< the version of the client that is connecting */
char strDeviceName[13]; /*!< the device name to use on the CEC bus */
char strDeviceName[LIBCEC_OSD_NAME_SIZE]; /*!< the device name to use on the CEC bus, name + 0 terminator */
cec_device_type_list deviceTypes; /*!< the device type(s) to use on the CEC bus for libCEC */
uint8_t bAutodetectAddress; /*!< (read only) set to 1 by libCEC when the physical address was autodetected */
uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter */
Expand Down Expand Up @@ -1513,7 +1519,7 @@ struct libcec_configuration
bool operator==(const libcec_configuration &other) const
{
return ( clientVersion == other.clientVersion &&
!strncmp(strDeviceName, other.strDeviceName, 13) &&
!strcmp(strDeviceName, other.strDeviceName) &&
deviceTypes == other.deviceTypes &&
bAutodetectAddress == other.bAutodetectAddress &&
iPhysicalAddress == other.iPhysicalAddress &&
Expand Down Expand Up @@ -1581,7 +1587,7 @@ struct libcec_configuration
bAutoPowerOn = 0;
#endif

memset(strDeviceName, 0, 13);
strDeviceName[0] = (char)0;
deviceTypes.Clear();
logicalAddresses.Clear();
wakeDevices.Clear();
Expand Down
4 changes: 2 additions & 2 deletions src/cec-client/cec-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
{
if (argc >= iArgPtr + 2)
{
snprintf(g_config.strDeviceName, 13, "%s", argv[iArgPtr + 1]);
snprintf(g_config.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", argv[iArgPtr + 1]);
std::cout << "using osd name " << g_config.strDeviceName << std::endl;
++iArgPtr;
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ int main (int argc, char *argv[])

g_config.Clear();
g_callbacks.Clear();
snprintf(g_config.strDeviceName, 13, "CECTester");
snprintf(g_config.strDeviceName, LIBCEC_OSD_NAME_SIZE, "CECTester");
g_config.clientVersion = LIBCEC_VERSION_CURRENT;
g_config.bActivateSource = 0;
g_callbacks.logMessage = &CecLogMessage;
Expand Down
6 changes: 3 additions & 3 deletions src/libcec/CECClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration)
{
CLockObject lock(m_mutex);

snprintf(configuration.strDeviceName, 13, "%s", m_configuration.strDeviceName);
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", m_configuration.strDeviceName);
configuration.deviceTypes = m_configuration.deviceTypes;
configuration.bAutodetectAddress = m_configuration.bAutodetectAddress;
configuration.iPhysicalAddress = m_configuration.iPhysicalAddress;
Expand Down Expand Up @@ -1274,7 +1274,7 @@ void CCECClient::SetOSDName(const std::string &strDeviceName)
{
{
CLockObject lock(m_mutex);
snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName.c_str());
snprintf(m_configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strDeviceName.c_str());
}

LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, strDeviceName.c_str());
Expand Down Expand Up @@ -1717,4 +1717,4 @@ bool CCECClient::GetStats(struct cec_adapter_stats* stats)
m_processor->GetStats(stats) :
false;
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/libcec/CECProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ bool CCECProcessor::RegisterClient(CECClientPtr client)
configuration.deviceTypes = config.deviceTypes;
if (CLibCEC::IsValidPhysicalAddress(config.iPhysicalAddress))
configuration.iPhysicalAddress = config.iPhysicalAddress;
snprintf(configuration.strDeviceName, 13, "%s", config.strDeviceName);
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", config.strDeviceName);
}

// set the firmware version and build date
Expand Down
4 changes: 2 additions & 2 deletions src/libcec/LibCEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types)
libcec_configuration configuration; configuration.Clear();

// client version < 1.5.0
snprintf(configuration.strDeviceName, 13, "%s", strDeviceName);
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strDeviceName);
configuration.deviceTypes = types;
configuration.iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS;

Expand Down Expand Up @@ -632,4 +632,4 @@ bool CLibCEC::GetStats(struct cec_adapter_stats* stats)
m_client->GetStats(stats) :
false;
}
#endif
#endif
5 changes: 4 additions & 1 deletion src/libcec/LibCECC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ int libcec_get_device_osd_name(libcec_connection_t connection, cec_logical_addre
if (!!adapter)
{
std::string osdName(adapter->GetDeviceOSDName(iAddress));
strncpy(name, osdName.c_str(), std::min(sizeof(cec_osd_name), osdName.size()));
size_t osd_size(osdName.size());
memcpy(name, osdName.c_str(), std::min(sizeof(cec_osd_name), osd_size));
if (osd_size < sizeof(cec_osd_name))
name[osd_size] = (char)0;
return 0;
}
return -1;
Expand Down
10 changes: 5 additions & 5 deletions src/libcec/adapter/Pulse-Eight/USBCECAdapterCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ bool CUSBCECAdapterCommands::RequestSettingOSDName(void)
if (response.size == 0)
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting");
memset(m_persistedConfiguration.strDeviceName, 0, 13);
m_persistedConfiguration.strDeviceName[0] = (char)0;
return false;
}

memcpy(m_persistedConfiguration.strDeviceName, response.data, response.size <= 13 ? response.size : 13);
if (response.size < 13) {
memcpy(m_persistedConfiguration.strDeviceName, response.data, response.size <= LIBCEC_OSD_NAME_SIZE ? response.size : LIBCEC_OSD_NAME_SIZE);
if (response.size < LIBCEC_OSD_NAME_SIZE) {
m_persistedConfiguration.strDeviceName[response.size] = (char)0;
}
return true;
Expand Down Expand Up @@ -511,7 +511,7 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName)
SAFE_DELETE(message);

if (bReturn)
snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", strOSDName);
snprintf(m_persistedConfiguration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strOSDName);

return bReturn;
}
Expand Down Expand Up @@ -623,7 +623,7 @@ bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuratio
configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion;
configuration.deviceTypes = m_persistedConfiguration.deviceTypes;
configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress;
snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName);
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", m_persistedConfiguration.strDeviceName);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcec/implementations/CECCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ int CCECCommandHandler::HandleSetOSDName(const cec_command &command)
CCECBusDevice *device = GetDevice(command.initiator);
if (device)
{
char buf[1024];
char buf[17];
for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
buf[iPtr] = (char)command.parameters[iPtr];
buf[command.parameters.size] = 0;
Expand Down

0 comments on commit b6f8e69

Please sign in to comment.