Add some bounds checking to the HDMI port number. bugzid: 508
authorMark Kendall <mkendall@mythtv.org>
Thu, 29 Mar 2012 07:15:44 +0000 (08:15 +0100)
committerMark Kendall <mkendall@mythtv.org>
Thu, 29 Mar 2012 07:15:44 +0000 (08:15 +0100)
src/cec-config/cec-config.cpp
src/lib/CECProcessor.cpp
src/testclient/main.cpp

index 456369180c069a9a66122ef720314cf38249cab5..b7a278beb354f6d598b184b2dd1bef41a6e6c017 100644 (file)
@@ -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 <enter>. 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 <enter>. 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)
index 96b5c7349db3a7253250d172f0fc87970ed638c0..095fb63335fed7322d71506df85d607abe9f1caf 100644 (file)
@@ -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;
index 1e1eea3b3560a149762c94c8abf8d09e04500ecb..1621ad34b1d80b437409bc805765c2bc460d5b2f 100644 (file)
@@ -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;
         }