Changeset - r27048:0ed975e7fe6d
[Not reviewed]
master
0 1 0
Jonathan G Rennison - 15 months ago 2023-03-22 16:46:40
j.g.rennison@gmail.com
Fix 41b414b: Validate RAW_STRING parameter values in game_script mode
1 file changed with 12 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/strings.cpp
Show inline comments
 
@@ -799,6 +799,9 @@ uint ConvertDisplaySpeedToKmhishSpeed(ui
 
{
 
	return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10);
 
}
 

	
 
static std::vector<const char *> _game_script_raw_strings;
 

	
 
/**
 
 * Parse most format codes within a string and write the result to a buffer.
 
 * @param buff    The buffer to write the final string to.
 
@@ -932,6 +935,7 @@ static char *FormatString(char *buff, co
 

	
 
						sub_args_need_free[i] = true;
 
						sub_args.SetParam(i++, (uint64)(size_t)g);
 
						_game_script_raw_strings.push_back(g);
 
					}
 
				}
 
				/* If we didn't error out, we can actually print the string. */
 
@@ -941,7 +945,10 @@ static char *FormatString(char *buff, co
 
				}
 

	
 
				for (i = 0; i < 20; i++) {
 
					if (sub_args_need_free[i]) free((void *)sub_args.GetParam(i));
 
					if (sub_args_need_free[i]) {
 
						free((void *)sub_args.GetParam(i));
 
						_game_script_raw_strings.pop_back();
 
					}
 
				}
 
				break;
 
			}
 
@@ -1046,6 +1053,10 @@ static char *FormatString(char *buff, co
 

	
 
			case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
 
				const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
 
				if (game_script && std::find(_game_script_raw_strings.begin(), _game_script_raw_strings.end(), raw_string) == _game_script_raw_strings.end()) {
 
					buff = strecat(buff, "(invalid RAW_STRING parameter)", last);
 
					break;
 
				}
 
				buff = FormatString(buff, raw_string, args, last);
 
				break;
 
			}
0 comments (0 inline, 0 general)