Skip to content

[nxn-shop] getShop és getAllShops exportok belső referenciát adnak vissza – külső resource módosíthatja a bolt defíniciókat #181

Description

@firstvideosgrp

🐛 Bug leírás

A getShop és getAllShops exportok közvetlenül a belső táblákat adják vissza referencia szerint:

exports('getShop', function(shopId)
    return GetShopDef(shopId)  -- ❌ belso referencia!
end)

exports('getAllShops', function()
    return GetAllShopDefs()    -- ❌ uj tabla, de az ertekek referencia!
end)

A GetAllShopDefs() ugyan új all táblát hoz létre, de az értékek referencia szerint kerülnek be:

for k, v in pairs(Config.Shops) do all[k] = v end  -- ❌ v referencia!

Külső resource:

local shop = exports['nxn-shop']:getShop('pawn_shop_1')
shop.items = {}  -- ❌ torli a bolt items tablajat!
shop.canSell = true  -- ❌ modositja a belso allapotot!

local all = exports['nxn-shop']:getAllShops()
all['pawn_shop_1'].label = 'Hacked'  -- ❌ Config.Shops-t modositja!

Ugyanaz az antipattern mint #79, #102, #110 issue-kban.

📍 Érintett fájl

nxn-shop/server.luagetShop, getAllShops exportok

✅ Javasolt javítás

exports('getShop', function(shopId)
    local shop = GetShopDef(shopId)
    if not shop then return nil end
    local copy = {}
    for k, v in pairs(shop) do
        copy[k] = (type(v) == 'table') and (function(t)
            local c = {}
            for k2,v2 in pairs(t) do c[k2]=v2 end
            return c
        end)(v) or v
    end
    return copy
end)

exports('getAllShops', function()
    local all = GetAllShopDefs()
    local copy = {}
    for shopId, shop in pairs(all) do
        copy[shopId] = {}
        for k, v in pairs(shop) do copy[shopId][k] = v end
    end
    return copy
end)

🏷️ Prioritás

Közepes – külső resource véletlenszerűen törölheti vagy módosíthatja a bolt adatait és az item listákat.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnxn-shop

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions