File 0157-kernel-prevent-crash-when-calling-io-getopts-when-us.patch of Package erlang

From db261e822a7eb62ac44078d395db47685fe7e79e Mon Sep 17 00:00:00 2001
From: Fredrik Frantzen <frazze@erlang.org>
Date: Wed, 15 Oct 2025 10:05:04 +0200
Subject: [PATCH] kernel: prevent crash when calling io:getopts when user_drv
 is down

---
 lib/kernel/src/group.erl | 10 +++++++---
 lib/stdlib/src/shell.erl |  7 +++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/kernel/src/group.erl b/lib/kernel/src/group.erl
index f122a0ec65..146250bcd0 100644
--- a/lib/kernel/src/group.erl
+++ b/lib/kernel/src/group.erl
@@ -800,9 +800,13 @@ getopts(Data) ->
                          true -> unicode;
                          _ -> latin1
                      end},
-    Terminal = get_terminal_state(Data#state.driver),
-    Tty = {terminal, maps:get(stdout, Terminal)},
-    [Exp,Echo,LineHistory,Log,Bin,Uni,Tty|maps:to_list(Terminal)].
+    case get_terminal_state(Data#state.driver) of
+        Terminal when is_map(Terminal) ->
+            Tty = {terminal, maps:get(stdout, Terminal)},
+            [Exp,Echo,LineHistory,Log,Bin,Uni,Tty|maps:to_list(Terminal)];
+        Error ->
+            Error
+    end.
 
 %% Convert error code to make it look as before
 err_func(io_lib, get_until, {_,F,_}) ->
diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl
index 5e7af7b439..0ac830f12b 100644
--- a/lib/stdlib/src/shell.erl
+++ b/lib/stdlib/src/shell.erl
@@ -397,8 +397,11 @@ get_command(Prompt, Eval, Bs, RT, FT, Ds) ->
     Parse =
         fun() ->
                 put('$ancestors', Ancestors),
-                PreviousHistory = proplists:get_value(line_history, io:getopts()),
-                [ok = io:setopts([{line_history, true}]) || PreviousHistory =/= undefined],
+                PreviousHistory = case io:getopts() of
+                        {error,_} -> undefined;
+                        Opts0 -> proplists:get_value(line_history, Opts0)
+                    end,
+                _ = [io:setopts([{line_history, true}]) || PreviousHistory =/= undefined],
                 Res = io:scan_erl_exprs(group_leader(), Prompt, {1,1},
                                         [text,{reserved_word_fun,ResWordFun}]),
                 _ = [io:setopts([{line_history, PreviousHistory}]) || PreviousHistory =/= undefined],
-- 
2.51.0

openSUSE Build Service is sponsored by