Bug #86567 MySQL Shell crashes if custom prompt has runtime error
Submitted: 2 Jun 2017 20:10 Modified: 26 Jul 2017 15:08
Reporter: Mario Beck Email Updates:
Status: Won't fix Impact on me:
None 
Category:Shell General / Core Client Severity:S3 (Non-critical)
Version:1.0.9 OS:Any
Assigned to: CPU Architecture:Any
Tags: core, custom prompt

[2 Jun 2017 20:10] Mario Beck
Description:
If I define a function for the custom prompt and that function creates a runtime error, mysqlsh coredumps.
In the example below I wanted to print the current schema name as a prompt. After the connect there is no default schema selected.
session.getSchema returns NULL. Calling the getName method creates an error which cause shell to crash.

How to repeat:
[testy@localhost Intralot]$ mysqlsh
Welcome to MySQL Shell 1.0.9

Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type '\help', '\h' or '\?' for help, type '\quit' or '\q' to exit.

Currently in JavaScript mode. Use \sql to switch to SQL mode and execute queries.
mysql-js> \c root:root@localhost:4003
Creating a Session to 'root@localhost:4003'
Classic Session successfully established. No default schema selected.
mysql-js> shell.customPrompt=function(){return session.getCurrentSchema().getName();}

Segmentation fault (core dumped)

Suggested fix:
Use an error message in the prompt instead of crashing.
[5 Jun 2017 7:05] MySQL Verification Team
Hello Mario Beck,

Thank you for the report.

Thanks,
Umesh
[5 Jun 2017 7:15] MySQL Verification Team
#######
root@fedora25 ushastry]#  mysqlsh 
Welcome to MySQL Shell 1.0.9

Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type '\help', '\h' or '\?' for help, type '\quit' or '\q' to exit.

Currently in JavaScript mode. Use \sql to switch to SQL mode and execute queries.
mysql-js> 
mysql-js> \c root:root@localhost:33060
Creating a Session to 'root@localhost:33060'
Node Session successfully established. No default schema selected.
mysql-js> 
mysql-js> shell.customPrompt=function(){return session.getCurrentSchema().getName();}

Segmentation fault (core dumped)
[root@fedora25 ushastry]# 

##
(gdb) bt
#0  0x0000000000884e5d in shcore::JScript_type_bridger::v8_value_to_shcore_value(v8::Handle<v8::Value> const&) ()
#1  0x00000000007a3c40 in shcore::JScript_context::v8_value_to_shcore_value(v8::Handle<v8::Value> const&) ()
#2  0x00000000008bf924 in shcore::JScript_function::invoke(shcore::Argument_list const&) ()
#3  0x00000000008b5579 in shcore::JScript_function_wrapper::call(v8::FunctionCallbackInfo<v8::Value> const&) ()
#4  0x0000000000c1d07d in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#5  0x000000000098c467 in v8::internal::HandleApiCallAsFunctionOrConstructor(v8::internal::Isolate*, bool, v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)0>) ()
#6  0x000000000098c528 in v8::internal::Builtin_HandleApiCallAsFunction(int, v8::internal::Object**, v8::internal::Isolate*) ()
#7  0x000014f0106060a2 in ?? ()
#8  0x000014f010606001 in ?? ()
#9  0x00007ffe29ae1860 in ?? ()
#10 0x00007ffe29ae18a8 in ?? ()
#11 0x000014f01061ef3c in ?? ()
#12 0x0000313a00098341 in ?? ()
#13 0x00003e987d212d19 in ?? ()
#14 0x000014f01061ee81 in ?? ()
#15 0x0000000800000000 in ?? ()
#16 0x0000000000000000 in ?? ()
(gdb)
[26 Jul 2017 15:08] Alfredo Kojima
Posted by developer:
 
This feature has been deprecated and replaced in 8.0, thus this bug will not be fixed.