Changeset - r20017:784b9ac8f55a
[Not reviewed]
master
0 1 0
peter1138 - 11 years ago 2013-02-05 21:38:38
peter1138@openttd.org
(svn r24973) -Fix [FS#5462]: Prevent access to tile-based variables when tile is invalid.
1 file changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/newgrf_industries.cpp
Show inline comments
 
@@ -216,25 +216,27 @@ static uint32 GetCountAndDistanceOfClose
 
				if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
 
					if (this->industry->prod_level == 0) return 0;
 
					return min(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level, (uint16)0xFFFF);
 
				} else {
 
					return min(this->industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
 
				}
 
			} else {
 
				return 0;
 
			}
 
		}
 

	
 
		/* Manhattan distance of closes dry/water tile */
 
		case 0x43: return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
 
		case 0x43:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
 

	
 
		/* Layout number */
 
		case 0x44: return this->industry->selected_layout;
 

	
 
		/* Company info */
 
		case 0x45: {
 
			byte colours = 0;
 
			bool is_ai = false;
 

	
 
			const Company *c = Company::GetIfValid(this->industry->founder);
 
			if (c != NULL) {
 
				const Livery *l = &c->livery[LS_DEFAULT];
 
@@ -244,46 +246,56 @@ static uint32 GetCountAndDistanceOfClose
 
			}
 

	
 
			return this->industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
 
		}
 

	
 
		case 0x46: return this->industry->construction_date; // Date when built - long format - (in days)
 

	
 
		/* Get industry ID at offset param */
 
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->industry->location.tile, false), this->industry, this->ro->grffile->grfid);
 

	
 
		/* Get random tile bits at offset param */
 
		case 0x61: {
 
			if (this->tile == INVALID_TILE) break;
 
			TileIndex tile = GetNearbyTile(parameter, this->tile, false);
 
			return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
 
		}
 

	
 
		/* Land info of nearby tiles */
 
		case 0x62: return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro->grffile->grf_version >= 8);
 
		case 0x62:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro->grffile->grf_version >= 8);
 

	
 
		/* Animation stage of nearby tiles */
 
		case 0x63: {
 
			if (this->tile == INVALID_TILE) break;
 
			TileIndex tile = GetNearbyTile(parameter, this->tile, false);
 
			if (this->industry->TileBelongsToIndustry(tile)) {
 
				return GetAnimationFrame(tile);
 
			}
 
			return 0xFFFFFFFF;
 
		}
 

	
 
		/* Distance of nearest industry of given type */
 
		case 0x64: return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
 
		case 0x64:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
 
		/* Get town zone and Manhattan distance of closest town */
 
		case 0x65: return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceManhattan(this->tile, this->industry->town->xy), 0xFFFF);
 
		case 0x65:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceManhattan(this->tile, this->industry->town->xy), 0xFFFF);
 
		/* Get square of Euclidian distance of closes town */
 
		case 0x66: return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceSquare(this->tile, this->industry->town->xy), 0xFFFF);
 
		case 0x66:
 
			if (this->tile == INVALID_TILE) break;
 
			return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceSquare(this->tile, this->industry->town->xy), 0xFFFF);
 

	
 
		/* Count of industry, distance of closest instance
 
		 * 68 is the same as 67, but with a filtering on selected layout */
 
		case 0x67:
 
		case 0x68: {
 
			byte layout_filter = 0;
 
			bool town_filter = false;
 
			if (variable == 0x68) {
 
				uint32 reg = GetRegister(0x101);
 
				layout_filter = GB(reg, 0, 8);
 
				town_filter = HasBit(reg, 8);
 
			}
0 comments (0 inline, 0 general)