Bug #70742 [Nab]: random_bytes() fails when the SYSTEMROOT env var is empty

From: Date: Tue, 20 Oct 2015 13:09:02 +0000
Subject: Bug #70742 [Nab]: random_bytes() fails when the SYSTEMROOT env var is empty
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196705@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70742&edit=1

 ID:                 70742
 User updated by:    nicolas dot grekas+php at gmail dot com
 Reported by:        nicolas dot grekas+php at gmail dot com
 Summary:            random_bytes() fails when the SYSTEMROOT env var is
                     empty
 Status:             Not a bug
 Type:               Bug
 Package:            mcrypt related
 Operating System:   Windows
 PHP Version:        7.0.0RC5
 Block user comment: N
 Private report:     N

 New Comment:

"Not a bug" is fine by me, I mostly wanted to get feedback on this behaviour and document
it somewhere.
This can happen more frequently by using proc_open(): when one sets the $env argument, it's
easy to miss some important vars there.


Previous Comments:
------------------------------------------------------------------------
[2015-10-20 11:16:03] ab@php.net

Thanks for the report. Why would you want to manipulate this env variable? Doing so, you'll
probably break not only this but many other things.

In this particular case, since the default crypto service provider is used, the corresponding DLL
will fail to load. Consequently CryptAcquireContext() will fail. This is expected behavior.

Thanks.

------------------------------------------------------------------------
[2015-10-19 14:56:06] nicolas dot grekas+php at gmail dot com

Description:
------------
On Windows, both random_bytes and mcrypt_create_iv fail when the SYSTEMROOT env var is not set.

Test script:
---------------
<?php

putenv('SYSTEMROOT=');

echo strlen(random_bytes(1));

Expected result:
----------------
1

Actual result:
--------------
PHP Warning:  mcrypt_create_iv(): Could not gather sufficient random data


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70742&edit=1


Thread (4 messages)

« previous php.bugs (#196705) next »