[OpenBIOS] [PATCH 6/7] ciface.fs: handle buggy callers to test-method

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sun May 4 19:49:54 CEST 2014


SPARC64 *BSDs accidentally call test-method with an ihandle rather than a
phandle which causes OpenBIOS to crash. Work around this by checking to
ensure that the phandle exists within the tree before trying to use it.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/forth/system/ciface.fs |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/openbios-devel/forth/system/ciface.fs b/openbios-devel/forth/system/ciface.fs
index 727f0a3..fc40cff 100644
--- a/openbios-devel/forth/system/ciface.fs
+++ b/openbios-devel/forth/system/ciface.fs
@@ -55,6 +55,17 @@ variable callback-function
   ." <" dup cstrlen dup 20 < if type else 2drop ." BAD" then ." >"
 ;
 
+: phandle-exists?  ( phandle -- found? )
+  false swap 0
+  begin iterate-tree ?dup while
+    ( found? find-ph current-ph )
+    over over = if
+      rot drop true -rot
+    then
+  repeat
+  drop
+;
+
 \ -------------------------------------------------------------
 \ public interface
 \ -------------------------------------------------------------
@@ -317,11 +328,15 @@ external
   outer-interpreter
 ;
 
-( cstring-method phandle -- missing )
-
-: test-method
-	swap dup cstrlen rot
-	find-method 0= if -1 else drop 0 then
+: test-method    ( cstring-method phandle -- missing? )
+  swap dup cstrlen rot
+  
+  \ Check for incorrect phandle
+  dup phandle-exists? false = if
+    -1 throw
+  then
+  
+  find-method 0= if -1 else drop 0 then
 ;
 
 finish-device
-- 
1.7.10.4




More information about the OpenBIOS mailing list