You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ps...@apache.org on 2022/04/11 08:47:59 UTC

[hbase] branch branch-2.5 updated: HBASE-26880 Misspelling commands in hbase shell will crash the shell (#4325)

This is an automated email from the ASF dual-hosted git repository.

psomogyi pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.5 by this push:
     new 5e6042b1ca2 HBASE-26880 Misspelling commands in hbase shell will crash the shell (#4325)
5e6042b1ca2 is described below

commit 5e6042b1ca29a2393bd574cc666542b48e285207
Author: Peter Somogyi <ps...@apache.org>
AuthorDate: Mon Apr 11 10:01:24 2022 +0200

    HBASE-26880 Misspelling commands in hbase shell will crash the shell (#4325)
    
    Signed-off-by: Andrew Purtell <ap...@apache.org>
---
 hbase-shell/src/main/ruby/irb/hirb.rb      | 10 +++++++---
 hbase-shell/src/main/ruby/jar-bootstrap.rb |  4 ++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/hbase-shell/src/main/ruby/irb/hirb.rb b/hbase-shell/src/main/ruby/irb/hirb.rb
index 9a81f5abc77..7fc40912489 100644
--- a/hbase-shell/src/main/ruby/irb/hirb.rb
+++ b/hbase-shell/src/main/ruby/irb/hirb.rb
@@ -23,7 +23,7 @@ module IRB
 
   # Subclass of IRB so can intercept methods
   class HIRB < Irb
-    def initialize(workspace = nil, input_method = nil)
+    def initialize(workspace = nil, interactive = true, input_method = nil)
       # This is ugly.  Our 'help' method above provokes the following message
       # on irb construction: 'irb: warn: can't alias help from irb_help.'
       # Below, we reset the output so its pointed at /dev/null during irb
@@ -46,6 +46,7 @@ module IRB
       if $stdin.tty?
         `stty icrnl <&2`
       end
+      @interactive = interactive
       super(workspace, input_method)
     ensure
       f.close
@@ -117,11 +118,14 @@ module IRB
           rescue Interrupt => exc
           rescue SystemExit, SignalException
             raise
-          rescue Exception
+          rescue NameError => exc
+            raise exc unless @interactive
+            # HBASE-26880: Ignore NameError to prevent exiting Shell on mistyped commands.
+          rescue Exception => exc
             # HBASE-26741: Raise exception so Shell::exception_handler can catch it.
             # This modifies this copied method from JRuby so that the HBase shell can
             # manage the exception and set a proper exit code on the process.
-            raise
+            raise exc
           end
           if exc
             if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
diff --git a/hbase-shell/src/main/ruby/jar-bootstrap.rb b/hbase-shell/src/main/ruby/jar-bootstrap.rb
index ee2fe9fd21e..917817fc59f 100644
--- a/hbase-shell/src/main/ruby/jar-bootstrap.rb
+++ b/hbase-shell/src/main/ruby/jar-bootstrap.rb
@@ -213,7 +213,7 @@ workspace = @shell.get_workspace
 # script calls 'exit' or 'exit 0' or 'exit errcode'.
 if script2run
   ::Shell::Shell.exception_handler(!full_backtrace) do
-    IRB::HIRB.new(workspace, IRB::HBaseLoader.file_for_load(script2run)).run
+    IRB::HIRB.new(workspace, interactive, IRB::HBaseLoader.file_for_load(script2run)).run
   end
   exit @shell.exit_code unless @shell.exit_code.nil?
 end
@@ -222,5 +222,5 @@ if interactive
   # Output a banner message that tells users where to go for help
   @shell.print_banner
 end
-IRB::HIRB.new(workspace).run
+IRB::HIRB.new(workspace, interactive).run
 exit @shell.exit_code unless interactive || @shell.exit_code.nil?