Fix stack overflow if printing a pre-boot error throws an error
authorAndy Wingo <wingo@pobox.com>
Mon, 25 Nov 2019 08:46:13 +0000 (09:46 +0100)
committerAndy Wingo <wingo@pobox.com>
Mon, 25 Nov 2019 08:46:58 +0000 (09:46 +0100)
* libguile/throw.c (scm_throw): Fall back to fprintf if all is lost.

libguile/throw.c

index 9c89c6511936b51b9eaa1d22b4ffaff5c8c92285..e837abe897050c479a303d2007eadb61e2cac7e0 100644 (file)
@@ -243,11 +243,20 @@ scm_throw (SCM key, SCM args)
 {
   SCM throw = scm_variable_ref (throw_var);
   if (scm_is_false (throw)) {
-    SCM port = scm_current_error_port ();
-    scm_puts ("Pre-boot error; key: ", port);
-    scm_write (key, port);
-    scm_puts (", args: ", port);
-    scm_write (args, port);
+    static int error_printing_error = 0;
+    if (error_printing_error++)
+      {
+        fprintf (stderr, "Error while printing pre-boot error: %s\n",
+                 scm_i_symbol_chars (key));
+      }
+    else
+      {
+        SCM port = scm_current_error_port ();
+        scm_puts ("Pre-boot error; key: ", port);
+        scm_write (key, port);
+        scm_puts (", args: ", port);
+        scm_write (args, port);
+      }
     abort ();
   }
   scm_apply_1 (throw, key, args);