Skip to content

Commit 495d158

Browse files
ip2c: Add safety checks to exported function arguments (#414)
1 parent f0d0285 commit 495d158

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

[admin]/admin2/server/admin_server.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ function updatePlayerCountry(player)
154154
local isIP2CResourceRunning = getResourceFromName( "ip2c" )
155155
isIP2CResourceRunning = isIP2CResourceRunning and getResourceState( isIP2CResourceRunning ) == "running"
156156
aPlayers[player].country = isIP2CResourceRunning and exports.ip2c:getPlayerCountry(player) or false
157-
aPlayers[player].countryname = isIP2CResourceRunning and exports.ip2c:getCountryName(aPlayers[player].country) or false
157+
if aPlayers[player].country then
158+
aPlayers[player].countryname = isIP2CResourceRunning and exports.ip2c:getCountryName(aPlayers[player].country) or false
159+
end
158160
end
159161

160162
function aPlayerInitialize(player)

[admin]/ip2c/server.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ local IP2C_UPDATE_INTERVAL_SECONDS = 60 * 60 * 24 * 1 -- Update no more than onc
2020

2121
-- [Exported]
2222
function getPlayerCountry ( player )
23+
if not (isElement(player) and getElementType(player) == "player") then return false end
2324
if not loadIPGroupsIsReady() then return false end
2425
local ip = getPlayerIP(player)
2526
local ip_group = tonumber ( gettok ( ip, 1, 46 ) )

[admin]/ip2c/shared.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,8 @@ local countryListAlpha2 = {
255255

256256
-- [Exported]
257257
function getCountryName( country )
258+
if type(country) ~= "string" then
259+
return "Invalid country code"
260+
end
258261
return countryListAlpha2[ (string.upper(country)) ] or "Unknown"
259262
end

0 commit comments

Comments
 (0)