Tarantool development patches archive
 help / color / mirror / Atom feed
From: Olga Arkhangelskaia <arkholga@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2 2/2] box: protects box.cfg from raw data modification
Date: Fri, 22 Nov 2019 15:03:47 +0300	[thread overview]
Message-ID: <20191122120347.66629-3-arkholga@tarantool.org> (raw)
In-Reply-To: <20191122120347.66629-1-arkholga@tarantool.org>

Forbids the possibility of the raw modification for box.cfg table.
Now the only way to change table value is box.cfg{}.

Closes #2867
---
 src/box/lua/load_cfg.lua  | 14 +++++++++++++-
 test/box-tap/cfg.test.lua | 11 ++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 85617c8f0..27ac6bb77 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -533,12 +533,24 @@ local function load_cfg(cfg)
     end
     setmetatable(box, nil)
     box_configured = nil
-    box.cfg = setmetatable(cfg,
+
+    local actual = cfg
+    box.cfg = setmetatable({},
         {
             __newindex = function(table, index)
                 error('Attempt to modify a read-only table')
             end,
             __call = locked(reload_cfg),
+            __index = function (self, k)
+                return actual[k]
+            end,
+            __serialize = function() return actual end,
+            __pairs = function(self)
+                local function iter(actual, k)
+                    return next(actual, k)
+                end
+                return iter, actual, nil
+            end
         })
     private.cfg_load()
     for key, fun in pairs(dynamic_cfg) do
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index d529447bb..443dfafbc 100755
--- a/test/box-tap/cfg.test.lua
+++ b/test/box-tap/cfg.test.lua
@@ -6,7 +6,7 @@ local socket = require('socket')
 local fio = require('fio')
 local uuid = require('uuid')
 local msgpack = require('msgpack')
-test:plan(104)
+test:plan(105)
 
 --------------------------------------------------------------------------------
 -- Invalid values
@@ -592,6 +592,15 @@ box.cfg{read_only=true}
 ]]
 test:is(run_script(code), PANIC, "panic on bootstrapping a read-only instance as master")
 
+--
+-- gf-2867 raise on raw modifications of box.cfg values
+--
+code = [[
+box.cfg{}
+box.cfg["read_only"] = true
+]]
+
+test:is(run_script(code), PANIC, "attempt to modify a read-only table")
 
 test:check()
 os.exit(0)
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2019-11-22 12:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 12:03 [Tarantool-patches] [PATCH v2 0/2] " Olga Arkhangelskaia
2019-11-22 12:03 ` [Tarantool-patches] [PATCH v2 1/2] build: enables DLUAJIT_ENABLE_PAIRSMM by default Olga Arkhangelskaia
2019-11-22 13:45   ` Igor Munkin
2019-11-24 19:31     ` Igor Munkin
2019-11-22 12:03 ` Olga Arkhangelskaia [this message]
2019-11-22 16:31   ` [Tarantool-patches] [PATCH v2 2/2] box: protects box.cfg from raw data modification Igor Munkin
2019-11-22 16:55 ` [Tarantool-patches] [PATCH v2 0/2] " Igor Munkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191122120347.66629-3-arkholga@tarantool.org \
    --to=arkholga@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 2/2] box: protects box.cfg from raw data modification' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox