From 9d01baf21288c0c415851b9d66434cbcb1868857 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 27 Aug 2009 09:32:13 +0000
Subject: [PATCH] SimpleSAML_Utilities: Better error handling when opening
 /dev/urandom.

This code would create a loop in the error handler under windows.
Instead of trying to open the file, and handle the error, instead
check whether the file exists first.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1715 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index c4d9ae043..601ff46ca 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1122,7 +1122,11 @@ class SimpleSAML_Utilities {
 		assert('is_int($length)');
 
 		if($fp === NULL) {
-			$fp = @fopen('/dev/urandom', 'rb');
+			if (file_exists('/dev/urandom')) {
+				$fp = fopen('/dev/urandom', 'rb');
+			} else {
+				$fp = FALSE;
+			}
 		}
 
 		if($fp !== FALSE) {
-- 
GitLab