ソースを参照

Fixed some potential csv2yaml crashes (#5557)

Fixes #5549

Thanks to @Atemo
Lemongrass3110 4 年 前
コミット
602c6035e5
1 ファイル変更27 行追加5 行削除
  1. 27 5
      src/tool/csv2yaml.cpp

+ 27 - 5
src/tool/csv2yaml.cpp

@@ -3074,11 +3074,33 @@ static bool itemdb_read_db(const char* file) {
 
 		int type = atoi(str[3]), subtype = atoi(str[18]);
 
-		body << YAML::Key << "Type" << YAML::Value << name2Upper(constant_lookup(type, "IT_") + 3);
-		if (type == IT_WEAPON && subtype)
-			body << YAML::Key << "SubType" << YAML::Value << name2Upper(constant_lookup(subtype, "W_") + 2);
-		else if (type == IT_AMMO && subtype)
-			body << YAML::Key << "SubType" << YAML::Value << name2Upper(constant_lookup(subtype, "AMMO_") + 5);
+		const char* constant = constant_lookup( type, "IT_" );
+
+		if( constant == nullptr ){
+			ShowError( "itemdb_read_db: Unknown item type %d for item %u, skipping.\n", type, nameid );
+			continue;
+		}
+
+		body << YAML::Key << "Type" << YAML::Value << name2Upper( constant + 3 );
+		if( type == IT_WEAPON && subtype ){
+			constant = constant_lookup( subtype, "W_" );
+
+			if( constant == nullptr ){
+				ShowError( "itemdb_read_db: Unknown weapon type %d for item %u, skipping.\n", subtype, nameid );
+				continue;
+			}
+
+			body << YAML::Key << "SubType" << YAML::Value << name2Upper( constant + 2 );
+		}else if( type == IT_AMMO && subtype ){
+			constant = constant_lookup( subtype, "AMMO_" );
+
+			if( constant == nullptr ){
+				ShowError( "itemdb_read_db: Unknown ammo type %d for item %u, skipping.\n", subtype, nameid );
+				continue;
+			}
+
+			body << YAML::Key << "SubType" << YAML::Value << name2Upper(constant + 5);
+		}
 
 		if (atoi(str[4]) > 0)
 			body << YAML::Key << "Buy" << YAML::Value << atoi(str[4]);