mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 10:26:39 +00:00 
			
		
		
		
	Validate input bindings to avoid crashes
This commit is contained in:
		
							parent
							
								
									b21dc17538
								
							
						
					
					
						commit
						ad256e8343
					
				
					 1 changed files with 26 additions and 7 deletions
				
			
		
							
								
								
									
										25
									
								
								extern/oics/ICSInputControlSystem.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								extern/oics/ICSInputControlSystem.cpp
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -97,6 +97,13 @@ namespace ICS
 | 
				
			||||||
	            xmlControl = xmlControl->NextSiblingElement("Control");
 | 
						            xmlControl = xmlControl->NextSiblingElement("Control");
 | 
				
			||||||
	        }
 | 
						        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								static const size_t channelsCountLimit = 65536;
 | 
				
			||||||
 | 
								if (controlChannelCount > channelsCountLimit)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									ICS_LOG("Warning: requested channels count (" + ToString<size_t>(controlChannelCount) + ") exceeds allowed maximum (" + ToString<size_t>(channelsCountLimit) + "), clamping it");
 | 
				
			||||||
 | 
									controlChannelCount = channelsCountLimit;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(controlChannelCount > channelCount)
 | 
								if(controlChannelCount > channelCount)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				size_t dif = controlChannelCount - channelCount;
 | 
									size_t dif = controlChannelCount - channelCount;
 | 
				
			||||||
| 
						 | 
					@ -116,7 +123,13 @@ namespace ICS
 | 
				
			||||||
			TiXmlElement* xmlChannelFilter = xmlRoot->FirstChildElement("ChannelFilter");
 | 
								TiXmlElement* xmlChannelFilter = xmlRoot->FirstChildElement("ChannelFilter");
 | 
				
			||||||
			while(xmlChannelFilter)
 | 
								while(xmlChannelFilter)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				int ch = FromString<int>(xmlChannelFilter->Attribute("number"));
 | 
									size_t ch = FromString<size_t>(xmlChannelFilter->Attribute("number"));
 | 
				
			||||||
 | 
									if(ch >= controlChannelCount)
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										ICS_LOG("ERROR: channel number (ch) is out of range");
 | 
				
			||||||
 | 
										xmlChannelFilter = xmlChannelFilter->NextSiblingElement("ChannelFilter");
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				TiXmlElement* xmlInterval = xmlChannelFilter->FirstChildElement("Interval");
 | 
									TiXmlElement* xmlInterval = xmlChannelFilter->FirstChildElement("Interval");
 | 
				
			||||||
				while(xmlInterval)
 | 
									while(xmlInterval)
 | 
				
			||||||
| 
						 | 
					@ -150,7 +163,6 @@ namespace ICS
 | 
				
			||||||
					xmlInterval = xmlInterval->NextSiblingElement("Interval");
 | 
										xmlInterval = xmlInterval->NextSiblingElement("Interval");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
				xmlChannelFilter = xmlChannelFilter->NextSiblingElement("ChannelFilter");
 | 
									xmlChannelFilter = xmlChannelFilter->NextSiblingElement("ChannelFilter");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,7 +276,13 @@ namespace ICS
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					int chNumber = FromString<int>(xmlChannel->Attribute("number"));
 | 
										size_t chNumber = FromString<size_t>(xmlChannel->Attribute("number"));
 | 
				
			||||||
 | 
										if(chNumber >= controlChannelCount)
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											ICS_LOG("ERROR: channel number (chNumber) is out of range");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										else
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
						if(std::string(xmlChannel->Attribute("direction")) == "DIRECT")
 | 
											if(std::string(xmlChannel->Attribute("direction")) == "DIRECT")
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							mControls.back()->attachChannel(mChannels[ chNumber ],Channel::DIRECT, percentage);
 | 
												mControls.back()->attachChannel(mChannels[ chNumber ],Channel::DIRECT, percentage);
 | 
				
			||||||
| 
						 | 
					@ -273,6 +291,7 @@ namespace ICS
 | 
				
			||||||
						{
 | 
											{
 | 
				
			||||||
							mControls.back()->attachChannel(mChannels[ chNumber ],Channel::INVERSE, percentage);
 | 
												mControls.back()->attachChannel(mChannels[ chNumber ],Channel::INVERSE, percentage);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					xmlChannel = xmlChannel->NextSiblingElement("Channel");
 | 
										xmlChannel = xmlChannel->NextSiblingElement("Channel");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue