Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] box: fix bug with module_reload() without box.cfg{}
@ 2019-02-05  0:17 Roman Khabibov
  2019-02-05 15:41 ` [tarantool-patches] " Vladislav Shpilevoy
  2019-02-15 14:58 ` Kirill Yukhin
  0 siblings, 2 replies; 5+ messages in thread
From: Roman Khabibov @ 2019-02-05  0:17 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

Fix bug with segfault when use module_reload() before box.cfg{}.

Closes #3770

Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3770-module-reload
Issue: https://github.com/tarantool/tarantool/issues/3770
---
 src/box/func.c                | 3 +++
 test/box/func_reload.result   | 9 +++++++++
 test/box/func_reload.test.lua | 5 +++++
 3 files changed, 17 insertions(+)

diff --git a/src/box/func.c b/src/box/func.c
index a817851fd..ee6dd55dc 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -301,6 +301,9 @@ module_sym(struct module *module, const char *name)
 int
 module_reload(const char *package, const char *package_end, struct module **module)
 {
+	if (!modules)
+		return -1;
+
 	struct module *old_module = module_cache_find(package, package_end);
 	if (old_module == NULL) {
 		/* Module wasn't loaded - do nothing. */
diff --git a/test/box/func_reload.result b/test/box/func_reload.result
index b024cd143..e35ca41e2 100644
--- a/test/box/func_reload.result
+++ b/test/box/func_reload.result
@@ -1,3 +1,12 @@
+-- gh-3770 Check no segfault with module_reload() without box.cfg{}.
+box.internal.module_reload('')
+---
+- error: Module '' does not exist
+...
+box.internal.module_reload('xxx')
+---
+- error: Module 'xxx' does not exist
+...
 fio  = require('fio')
 ---
 ...
diff --git a/test/box/func_reload.test.lua b/test/box/func_reload.test.lua
index 8906898ec..00fe8cf48 100644
--- a/test/box/func_reload.test.lua
+++ b/test/box/func_reload.test.lua
@@ -1,3 +1,8 @@
+-- gh-3770 Check no segfault with module_reload() without box.cfg{}.
+
+box.internal.module_reload('')
+box.internal.module_reload('xxx')
+
 fio  = require('fio')
 net = require('net.box')
 fiber = require('fiber')
-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] box: fix bug with module_reload() without box.cfg{}
  2019-02-05  0:17 [tarantool-patches] [PATCH] box: fix bug with module_reload() without box.cfg{} Roman Khabibov
@ 2019-02-05 15:41 ` Vladislav Shpilevoy
  2019-02-07 11:31   ` Roman
  2019-02-15 14:58 ` Kirill Yukhin
  1 sibling, 1 reply; 5+ messages in thread
From: Vladislav Shpilevoy @ 2019-02-05 15:41 UTC (permalink / raw)
  To: tarantool-patches, Roman Khabibov

Hi! Thanks for the patch! See 5 comments below.

On 05/02/2019 01:17, Roman Khabibov wrote:
> Fix bug with segfault when use module_reload() before box.cfg{}.

1. Instead of duplicating commit title, it is usually
better to describe here a reason why the bug existed.

> 
> Closes #3770
> 
> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3770-module-reload
> Issue: https://github.com/tarantool/tarantool/issues/3770

2. Please, put branch and issue links after '---'.

> ---

Here.

>   src/box/func.c                | 3 +++
>   test/box/func_reload.result   | 9 +++++++++
>   test/box/func_reload.test.lua | 5 +++++
>   3 files changed, 17 insertions(+)
> 
> diff --git a/src/box/func.c b/src/box/func.c
> index a817851fd..ee6dd55dc 100644
> --- a/src/box/func.c
> +++ b/src/box/func.c
> @@ -301,6 +301,9 @@ module_sym(struct module *module, const char *name)
>   int
>   module_reload(const char *package, const char *package_end, struct module **module)
>   {
> +	if (!modules)
> +		return -1;

3. As you know, we use == NULL instead of ! when dealing with pointers.

4. Instead of checking for modules != NULL in each public func.h function,
it is better to move module_init() call from box_cfg_xc() to box_init(). Then
main() will create modules hash.

> +
>   	struct module *old_module = module_cache_find(package, package_end);
>   	if (old_module == NULL) {
>   		/* Module wasn't loaded - do nothing. */
> diff --git a/test/box/func_reload.test.lua b/test/box/func_reload.test.lua
> index 8906898ec..00fe8cf48 100644
> --- a/test/box/func_reload.test.lua
> +++ b/test/box/func_reload.test.lua
> @@ -1,3 +1,8 @@
> +-- gh-3770 Check no segfault with module_reload() without box.cfg{}.
> +
> +box.internal.module_reload('')
> +box.internal.module_reload('xxx')

5. Not-tap tests are always run with already called box.cfg(),
so these lines here will work regardless of your patch. Please,
move it to a tap test, in app-tap directory. Now I do not see
there any existing and suitable file for this test, so you
should create a new one. For example, app-tap/func.test.lua.

> +
>   fio  = require('fio')
>   net = require('net.box')
>   fiber = require('fiber')
> -- 
> 2.17.1
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] box: fix bug with module_reload() without box.cfg{}
  2019-02-05 15:41 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-02-07 11:31   ` Roman
  2019-02-15 13:28     ` Vladislav Shpilevoy
  0 siblings, 1 reply; 5+ messages in thread
From: Roman @ 2019-02-07 11:31 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Vladislav Shpilevoy

[-- Attachment #1: Type: text/plain, Size: 3341 bytes --]

Hi! Thanks for review.

On Вт, фев 5, 2019 at 6:42 PM, Vladislav Shpilevoy 
<v.shpilevoy@tarantool.org> wrote:
> Hi! Thanks for the patch! See 5 comments below.

> 1. Instead of duplicating commit title, it is usually
> better to describe here a reason why the bug existed.
Done.

> 
> 2. Please, put branch and issue links after '---'.
> 
>> ---
Sorry.

> 4. Instead of checking for modules != NULL in each public func.h 
> function,
> it is better to move module_init() call from box_cfg_xc() to 
> box_init(). Then
> main() will create modules hash.
diff --git a/src/box/box.cc b/src/box/box.cc
index 8892d0f0e..6494a0f44 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -2053,6 +2053,9 @@ box_init(void)
 	 */
 	session_init();

+	if (module_init() != 0)
+		diag_raise();
+
 	if (tuple_init(lua_hash) != 0)
 		diag_raise();

@@ -2080,8 +2083,6 @@ box_cfg_xc(void)

 	gc_init();
 	engine_init();
-	if (module_init() != 0)
-		diag_raise();
 	schema_init();
 	replication_init();
 	port_init();

> 5. Not-tap tests are always run with already called box.cfg(),
> so these lines here will work regardless of your patch. Please,
> move it to a tap test, in app-tap directory. Now I do not see
> there any existing and suitable file for this test, so you
> should create a new one. For example, app-tap/func.test.lua.
diff --git a/test/app-tap/func.test.lua b/test/app-tap/func.test.lua
new file mode 100755
index 000000000..11bc01f1d
--- /dev/null
+++ b/test/app-tap/func.test.lua
@@ -0,0 +1,14 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+
+local test = tap.test("func")
+
+test:plan(2)
+
+-- gh-3770 Check no segfault with module_reload() without box.cfg{}.
+
+test:ok(not pcall(box.internal.module_reload, ''),
+        'expected error: no module')
+test:ok(not pcall(box.internal.module_reload, 'xxx'),
+        'expected error: no module')


commit afd765d8bc86188c33cba3f06478853ec76bcaea
Author: Roman Khabibov <roman.habibov@tarantool.org>
Date:   Tue Feb 5 03:04:33 2019 +0300

    box: fix bug with module_reload() without box.cfg{}

    A bug existed because module_init was called during a call to 
box_cfg{}.
    Modules were not initialized before calling box.cfg{}.

    Closes #3770

diff --git a/src/box/box.cc b/src/box/box.cc
index 8892d0f0e..6494a0f44 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -2053,6 +2053,9 @@ box_init(void)
 	 */
 	session_init();

+	if (module_init() != 0)
+		diag_raise();
+
 	if (tuple_init(lua_hash) != 0)
 		diag_raise();

@@ -2080,8 +2083,6 @@ box_cfg_xc(void)

 	gc_init();
 	engine_init();
-	if (module_init() != 0)
-		diag_raise();
 	schema_init();
 	replication_init();
 	port_init();
diff --git a/test/app-tap/func.test.lua b/test/app-tap/func.test.lua
new file mode 100755
index 000000000..11bc01f1d
--- /dev/null
+++ b/test/app-tap/func.test.lua
@@ -0,0 +1,14 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+
+local test = tap.test("func")
+
+test:plan(2)
+
+-- gh-3770 Check no segfault with module_reload() without box.cfg{}.
+
+test:ok(not pcall(box.internal.module_reload, ''),
+        'expected error: no module')
+test:ok(not pcall(box.internal.module_reload, 'xxx'),
+        'expected error: no module')





[-- Attachment #2: Type: text/html, Size: 4424 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] box: fix bug with module_reload() without box.cfg{}
  2019-02-07 11:31   ` Roman
@ 2019-02-15 13:28     ` Vladislav Shpilevoy
  0 siblings, 0 replies; 5+ messages in thread
From: Vladislav Shpilevoy @ 2019-02-15 13:28 UTC (permalink / raw)
  To: Roman, tarantool-patches, Kirill Yukhin

LGTM.

On 07/02/2019 12:31, Roman wrote:
> Hi! Thanks for review.
> 
> On Вт, фев 5, 2019 at 6:42 PM, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>> Hi! Thanks for the patch! See 5 comments below. 
> 
>> 1. Instead of duplicating commit title, it is usually better to describe here a reason why the bug existed.
> Done.
> 
>> 2. Please, put branch and issue links after '---'.
>>
>>     ---
> Sorry.
> 
>> 4. Instead of checking for modules != NULL in each public func.h function, it is better to move module_init() call from box_cfg_xc() to box_init(). Then main() will create modules hash.
> diff --git a/src/box/box.cc b/src/box/box.cc index 8892d0f0e..6494a0f44 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2053,6 +2053,9 @@ box_init(void) */ session_init(); + if (module_init() != 0) + diag_raise(); + if (tuple_init(lua_hash) != 0) diag_raise(); @@ -2080,8 +2083,6 @@ box_cfg_xc(void) gc_init(); engine_init(); - if (module_init() != 0) - diag_raise(); schema_init(); replication_init(); port_init();
> 
>> 5. Not-tap tests are always run with already called box.cfg(), so these lines here will work regardless of your patch. Please, move it to a tap test, in app-tap directory. Now I do not see there any existing and suitable file for this test, so you should create a new one. For example, app-tap/func.test.lua. 
> diff --git a/test/app-tap/func.test.lua b/test/app-tap/func.test.lua new file mode 100755 index 000000000..11bc01f1d --- /dev/null +++ b/test/app-tap/func.test.lua @@ -0,0 +1,14 @@ +#!/usr/bin/env tarantool + +local tap = require('tap') + +local test = tap.test("func") + +test:plan(2) + +-- gh-3770 Check no segfault with module_reload() without box.cfg{}. + +test:ok(not pcall(box.internal.module_reload, ''), + 'expected error: no module') +test:ok(not pcall(box.internal.module_reload, 'xxx'), + 'expected error: no module')
> 
> 
> commit afd765d8bc86188c33cba3f06478853ec76bcaea Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Tue Feb 5 03:04:33 2019 +0300 box: fix bug with module_reload() without box.cfg{} A bug existed because module_init was called during a call to box_cfg{}. Modules were not initialized before calling box.cfg{}. Closes #3770 diff --git a/src/box/box.cc b/src/box/box.cc index 8892d0f0e..6494a0f44 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2053,6 +2053,9 @@ box_init(void) */ session_init(); + if (module_init() != 0) + diag_raise(); + if (tuple_init(lua_hash) != 0) diag_raise(); @@ -2080,8 +2083,6 @@ box_cfg_xc(void) gc_init(); engine_init(); - if (module_init() != 0) - diag_raise(); schema_init(); replication_init(); port_init(); diff --git a/test/app-tap/func.test.lua b/test/app-tap/func.test.lua new file mode 100755 index 000000000..11bc01f1d --- /dev/null +++ b/test/app-tap/func.test.lua @@ -0,0 +1,14 @@ +#!/usr/bin/env tarantool + +local tap = require('tap') + 
> +local test = tap.test("func") + +test:plan(2) + +-- gh-3770 Check no segfault with module_reload() without box.cfg{}. + +test:ok(not pcall(box.internal.module_reload, ''), + 'expected error: no module') +test:ok(not pcall(box.internal.module_reload, 'xxx'), + 'expected error: no module')
> 
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] box: fix bug with module_reload() without box.cfg{}
  2019-02-05  0:17 [tarantool-patches] [PATCH] box: fix bug with module_reload() without box.cfg{} Roman Khabibov
  2019-02-05 15:41 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-02-15 14:58 ` Kirill Yukhin
  1 sibling, 0 replies; 5+ messages in thread
From: Kirill Yukhin @ 2019-02-15 14:58 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

Hello,
On 05 Feb 03:17, Roman Khabibov wrote:
> Fix bug with segfault when use module_reload() before box.cfg{}.
> 
> Closes #3770
> 
> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3770-module-reload
> Issue: https://github.com/tarantool/tarantool/issues/3770

I've checked your patch into 2.1 branch.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-15 14:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-05  0:17 [tarantool-patches] [PATCH] box: fix bug with module_reload() without box.cfg{} Roman Khabibov
2019-02-05 15:41 ` [tarantool-patches] " Vladislav Shpilevoy
2019-02-07 11:31   ` Roman
2019-02-15 13:28     ` Vladislav Shpilevoy
2019-02-15 14:58 ` Kirill Yukhin

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