From 86393878734d316e04319c739dd45fc90c50bef8 Mon Sep 17 00:00:00 2001 From: Mark Kendall Date: Thu, 29 Mar 2012 08:15:44 +0100 Subject: [PATCH] Add some bounds checking to the HDMI port number. bugzid: 508 --- src/cec-config/cec-config.cpp | 11 ++++++++--- src/lib/CECProcessor.cpp | 6 ++++++ src/testclient/main.cpp | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cec-config/cec-config.cpp b/src/cec-config/cec-config.cpp index 4563691..b7a278b 100644 --- a/src/cec-config/cec-config.cpp +++ b/src/cec-config/cec-config.cpp @@ -228,13 +228,18 @@ bool OpenConnection(cec_device_type type = CEC_DEVICE_TYPE_RECORDING_DEVICE) int8_t FindPhysicalAddressPortNumber(void) { - PrintToStdOut("Enter the HDMI port number to which you connected your CEC adapter, followed by . Only port 1, 2, 3 or 4 are supported. Anything else will cancel this wizard."); + PrintToStdOut("Enter the HDMI port number to which you connected your CEC adapter, followed by . Valid ports are in the range 1-15. Anything else will cancel this wizard."); string input; getline(cin, input); cin.clear(); - if (input.empty() || (input != "1" && input != "2" && input != "3" && input != "4")) + if (input.empty()) return -1; - return (int8_t)atoi(input.c_str()); + + int8_t hdmiport = atoi(input.c_str()); + if (hdmiport < 1 || hdmiport > 15) + return -1; + + return hdmiport; } cec_logical_address FindPhysicalAddressBaseDevice(void) diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 96b5c73..095fb63 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -578,6 +578,12 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, { bool bReturn(false); + // limit the HDMI port range to 1-15 + if (iPort < 1) + iPort = 1; + if (iPort > 15) + iPort = 15; + { CLockObject lock(m_mutex); m_configuration.baseDevice = iBaseDevice; diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 1e1eea3..1621ad3 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -1023,7 +1023,12 @@ bool ProcessCommandLineArguments(int argc, char *argv[]) { if (argc >= iArgPtr + 2) { - g_config.iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]); + uint8_t hdmiport = (int8_t)atoi(argv[iArgPtr + 1]); + if (hdmiport < 1) + hdmiport = 1; + if (hdmiport > 15) + hdmiport = 15; + g_config.iHDMIPort = hdmiport; cout << "using HDMI port '" << (int)g_config.iHDMIPort << "'" << endl; ++iArgPtr; } -- 2.34.1