{"action":"created","comment":{"url":"https://api.github.com/repos/php/php-src/pulls/comments/25325747","id":25325747,"diff_hunk":"@@ -0,0 +1,169 @@\n+/*\n+   +----------------------------------------------------------------------+\n+   | PHP Version 7                                                        |\n+   +----------------------------------------------------------------------+\n+   | Copyright (c) 1997-2015 The PHP Group                                |\n+   +----------------------------------------------------------------------+\n+   | This source file is subject to version 3.01 of the PHP license,      |\n+   | that is bundled with this package in the file LICENSE, and is        |\n+   | available through the world-wide-web at the following url:           |\n+   | http://www.php.net/license/3_01.txt                                  |\n+   | If you did not receive a copy of the PHP license and are unable to   |\n+   | obtain it through the world-wide-web, please send a note to          |\n+   | license@php.net so we can mail you a copy immediately.               |\n+   +----------------------------------------------------------------------+\n+   | Authors: Sammy Kaye Powers <me@sammyk.me>                            |\n+   +----------------------------------------------------------------------+\n+*/\n+\n+/* $Id$ */\n+\n+#include <stdlib.h>\n+#include <sys/stat.h>\n+#include <fcntl.h>\n+#include <math.h>\n+\n+#include \"php.h\"\n+\n+#if PHP_WIN32\n+# include \"win32/winutil.h\"\n+#endif\n+\n+static int php_random_bytes(void *bytes, size_t size)\n+{\n+#if PHP_WIN32\n+\t/* Defer to CryptGenRandom on Windows */\n+\tif (php_win32_get_random_bytes(bytes, size) == FAILURE) {\n+\t\tphp_error_docref(NULL, E_WARNING, \"Could not gather sufficient random data\");\n+\t\treturn FAILURE;\n+\t}\n+#else\n+#if HAVE_DECL_ARC4RANDOM_BUF\n+\tarc4random_buf(bytes, size);\n+#else\n+\tint    fd = -1;\n+\tsize_t read_bytes = 0;\n+#if HAVE_DEV_ARANDOM\n+\tfd = open(\"/dev/arandom\", O_RDONLY);\n+#else\n+#if HAVE_DEV_URANDOM\n+\tfd = open(\"/dev/urandom\", O_RDONLY);\n+#endif // URANDOM\n+#endif // ARANDOM\n+\tif (fd < 0) {\n+\t\tphp_error_docref(NULL, E_WARNING, \"Cannot open source device\");\n+\t\treturn FAILURE;\n+\t}\n+\n+\tsize_t n = 0;\n+\twhile (read_bytes < size) {\n+\t\tn = read(fd, bytes + read_bytes, size - read_bytes);\n+\t\tif (n < 0) {\n+\t\t\tbreak;\n+\t\t}\n+\t\tread_bytes += n;\n+\t}\n+\n+\tclose(fd);\n+\tif (read_bytes < size) {\n+\t\tphp_error_docref(NULL, E_WARNING, \"Could not gather sufficient random data\");\n+\t\treturn FAILURE;\n+\t}\n+#endif // !ARC4RANDOM_BUF\n+#endif // !WIN32\n+\n+\treturn SUCCESS;\n+}\n+\n+/* {{{ proto string random_bytes(int length)\n+Return an arbitrary length of pseudo-random bytes as binary string */\n+PHP_FUNCTION(random_bytes)\n+{\n+\tzend_long size;\n+\tzend_string *bytes;\n+\n+\tif (zend_parse_parameters(ZEND_NUM_ARGS(), \"l\", &size) == FAILURE) {\n+\t\treturn;\n+\t}\n+\n+\tif (size < 1) {\n+\t\tphp_error_docref(NULL, E_WARNING, \"Length must be greater than 0\");\n+\t\tRETURN_FALSE;\n+\t}\n+\n+\tbytes = zend_string_alloc(size, 0);\n+\n+\tif (php_random_bytes(bytes->val, size) == FAILURE) {\n+\t\tzend_string_release(bytes);\n+\t\tRETURN_FALSE;\n+\t}\n+\n+\tbytes->val[size] = '\\0';\n+\n+\tRETURN_STR(bytes);\n+}\n+/* }}} */\n+\n+/* {{{ proto int random_int(int min, int max)\n+Return an arbitrary pseudo-random integer */\n+PHP_FUNCTION(random_int)\n+{\n+\tzend_long min = ZEND_LONG_MIN;\n+\tzend_long max = ZEND_LONG_MAX;\n+\tzend_ulong limit;\n+\tzend_ulong umax;\n+\tzend_ulong result;\n+\n+\tif (ZEND_NUM_ARGS() == 1) {\n+\t\tphp_error_docref(NULL, E_WARNING, \"A minimum and maximum value are expected, only minimum given\");","path":"ext/standard/random.c","position":118,"original_position":118,"commit_id":"c6fc3915c450a94ffeec40d66b720f80598299f0","original_commit_id":"c6fc3915c450a94ffeec40d66b720f80598299f0","user":{"login":"laruence","id":382813,"avatar_url":"https://avatars.githubusercontent.com/u/382813?v=3","gravatar_id":"","url":"https://api.github.com/users/laruence","html_url":"https://github.com/laruence","followers_url":"https://api.github.com/users/laruence/followers","following_url":"https://api.github.com/users/laruence/following{/other_user}","gists_url":"https://api.github.com/users/laruence/gists{/gist_id}","starred_url":"https://api.github.com/users/laruence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laruence/subscriptions","organizations_url":"https://api.github.com/users/laruence/orgs","repos_url":"https://api.github.com/users/laruence/repos","events_url":"https://api.github.com/users/laruence/events{/privacy}","received_events_url":"https://api.github.com/users/laruence/received_events","type":"User","site_admin":false},"body":"since you already have LONG_MIN and LONG_MAX, so if only minimum value min is given. then simply assume it means min to LONG_MAX?","created_at":"2015-02-25T09:03:18Z","updated_at":"2015-02-25T09:03:18Z","html_url":"https://github.com/php/php-src/pull/1119#discussion_r25325747","pull_request_url":"https://api.github.com/repos/php/php-src/pulls/1119","_links":{"self":{"href":"https://api.github.com/repos/php/php-src/pulls/comments/25325747"},"html":{"href":"https://github.com/php/php-src/pull/1119#discussion_r25325747"},"pull_request":{"href":"https://api.github.com/repos/php/php-src/pulls/1119"}}},"pull_request":{"url":"https://api.github.com/repos/php/php-src/pulls/1119","id":29944067,"html_url":"https://github.com/php/php-src/pull/1119","diff_url":"https://github.com/php/php-src/pull/1119.diff","patch_url":"https://github.com/php/php-src/pull/1119.patch","issue_url":"https://api.github.com/repos/php/php-src/issues/1119","number":1119,"state":"open","locked":false,"title":"[WIP] Easy User-land CSPRNG","user":{"login":"SammyK","id":578780,"avatar_url":"https://avatars.githubusercontent.com/u/578780?v=3","gravatar_id":"","url":"https://api.github.com/users/SammyK","html_url":"https://github.com/SammyK","followers_url":"https://api.github.com/users/SammyK/followers","following_url":"https://api.github.com/users/SammyK/following{/other_user}","gists_url":"https://api.github.com/users/SammyK/gists{/gist_id}","starred_url":"https://api.github.com/users/SammyK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SammyK/subscriptions","organizations_url":"https://api.github.com/users/SammyK/orgs","repos_url":"https://api.github.com/users/SammyK/repos","events_url":"https://api.github.com/users/SammyK/events{/privacy}","received_events_url":"https://api.github.com/users/SammyK/received_events","type":"User","site_admin":false},"body":"Submitting as a PR per @nikic's recommendation.\r\n\r\nRFC can be found [here](https://wiki.php.net/rfc/easy_userland_csprng).","created_at":"2015-02-24T22:48:22Z","updated_at":"2015-02-25T09:03:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"979455c51362dfd6a73229f77a4f0dd81e2fa622","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/php/php-src/pulls/1119/commits","review_comments_url":"https://api.github.com/repos/php/php-src/pulls/1119/comments","review_comment_url":"https://api.github.com/repos/php/php-src/pulls/comments{/number}","comments_url":"https://api.github.com/repos/php/php-src/issues/1119/comments","statuses_url":"https://api.github.com/repos/php/php-src/statuses/c6fc3915c450a94ffeec40d66b720f80598299f0","head":{"label":"SammyK:rand-bytes","ref":"rand-bytes","sha":"c6fc3915c450a94ffeec40d66b720f80598299f0","user":{"login":"SammyK","id":578780,"avatar_url":"https://avatars.githubusercontent.com/u/578780?v=3","gravatar_id":"","url":"https://api.github.com/users/SammyK","html_url":"https://github.com/SammyK","followers_url":"https://api.github.com/users/SammyK/followers","following_url":"https://api.github.com/users/SammyK/following{/other_user}","gists_url":"https://api.github.com/users/SammyK/gists{/gist_id}","starred_url":"https://api.github.com/users/SammyK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SammyK/subscriptions","organizations_url":"https://api.github.com/users/SammyK/orgs","repos_url":"https://api.github.com/users/SammyK/repos","events_url":"https://api.github.com/users/SammyK/events{/privacy}","received_events_url":"https://api.github.com/users/SammyK/received_events","type":"User","site_admin":false},"repo":{"id":20080767,"name":"php-src","full_name":"SammyK/php-src","owner":{"login":"SammyK","id":578780,"avatar_url":"https://avatars.githubusercontent.com/u/578780?v=3","gravatar_id":"","url":"https://api.github.com/users/SammyK","html_url":"https://github.com/SammyK","followers_url":"https://api.github.com/users/SammyK/followers","following_url":"https://api.github.com/users/SammyK/following{/other_user}","gists_url":"https://api.github.com/users/SammyK/gists{/gist_id}","starred_url":"https://api.github.com/users/SammyK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SammyK/subscriptions","organizations_url":"https://api.github.com/users/SammyK/orgs","repos_url":"https://api.github.com/users/SammyK/repos","events_url":"https://api.github.com/users/SammyK/events{/privacy}","received_events_url":"https://api.github.com/users/SammyK/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SammyK/php-src","description":"The PHP Interpreter","fork":true,"url":"https://api.github.com/repos/SammyK/php-src","forks_url":"https://api.github.com/repos/SammyK/php-src/forks","keys_url":"https://api.github.com/repos/SammyK/php-src/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SammyK/php-src/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SammyK/php-src/teams","hooks_url":"https://api.github.com/repos/SammyK/php-src/hooks","issue_events_url":"https://api.github.com/repos/SammyK/php-src/issues/events{/number}","events_url":"https://api.github.com/repos/SammyK/php-src/events","assignees_url":"https://api.github.com/repos/SammyK/php-src/assignees{/user}","branches_url":"https://api.github.com/repos/SammyK/php-src/branches{/branch}","tags_url":"https://api.github.com/repos/SammyK/php-src/tags","blobs_url":"https://api.github.com/repos/SammyK/php-src/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SammyK/php-src/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SammyK/php-src/git/refs{/sha}","trees_url":"https://api.github.com/repos/SammyK/php-src/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SammyK/php-src/statuses/{sha}","languages_url":"https://api.github.com/repos/SammyK/php-src/languages","stargazers_url":"https://api.github.com/repos/SammyK/php-src/stargazers","contributors_url":"https://api.github.com/repos/SammyK/php-src/contributors","subscribers_url":"https://api.github.com/repos/SammyK/php-src/subscribers","subscription_url":"https://api.github.com/repos/SammyK/php-src/subscription","commits_url":"https://api.github.com/repos/SammyK/php-src/commits{/sha}","git_commits_url":"https://api.github.com/repos/SammyK/php-src/git/commits{/sha}","comments_url":"https://api.github.com/repos/SammyK/php-src/comments{/number}","issue_comment_url":"https://api.github.com/repos/SammyK/php-src/issues/comments{/number}","contents_url":"https://api.github.com/repos/SammyK/php-src/contents/{+path}","compare_url":"https://api.github.com/repos/SammyK/php-src/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SammyK/php-src/merges","archive_url":"https://api.github.com/repos/SammyK/php-src/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SammyK/php-src/downloads","issues_url":"https://api.github.com/repos/SammyK/php-src/issues{/number}","pulls_url":"https://api.github.com/repos/SammyK/php-src/pulls{/number}","milestones_url":"https://api.github.com/repos/SammyK/php-src/milestones{/number}","notifications_url":"https://api.github.com/repos/SammyK/php-src/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SammyK/php-src/labels{/name}","releases_url":"https://api.github.com/repos/SammyK/php-src/releases{/id}","created_at":"2014-05-22T23:41:21Z","updated_at":"2015-02-10T08:12:22Z","pushed_at":"2015-02-25T00:04:24Z","git_url":"git://github.com/SammyK/php-src.git","ssh_url":"git@github.com:SammyK/php-src.git","clone_url":"https://github.com/SammyK/php-src.git","svn_url":"https://github.com/SammyK/php-src","homepage":"http://www.php.net","size":210193,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"php:master","ref":"master","sha":"dcb96c2e037e5198932385b573baea9a9dbf3252","user":{"login":"php","id":25158,"avatar_url":"https://avatars.githubusercontent.com/u/25158?v=3","gravatar_id":"","url":"https://api.github.com/users/php","html_url":"https://github.com/php","followers_url":"https://api.github.com/users/php/followers","following_url":"https://api.github.com/users/php/following{/other_user}","gists_url":"https://api.github.com/users/php/gists{/gist_id}","starred_url":"https://api.github.com/users/php/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php/subscriptions","organizations_url":"https://api.github.com/users/php/orgs","repos_url":"https://api.github.com/users/php/repos","events_url":"https://api.github.com/users/php/events{/privacy}","received_events_url":"https://api.github.com/users/php/received_events","type":"Organization","site_admin":false},"repo":{"id":1903522,"name":"php-src","full_name":"php/php-src","owner":{"login":"php","id":25158,"avatar_url":"https://avatars.githubusercontent.com/u/25158?v=3","gravatar_id":"","url":"https://api.github.com/users/php","html_url":"https://github.com/php","followers_url":"https://api.github.com/users/php/followers","following_url":"https://api.github.com/users/php/following{/other_user}","gists_url":"https://api.github.com/users/php/gists{/gist_id}","starred_url":"https://api.github.com/users/php/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php/subscriptions","organizations_url":"https://api.github.com/users/php/orgs","repos_url":"https://api.github.com/users/php/repos","events_url":"https://api.github.com/users/php/events{/privacy}","received_events_url":"https://api.github.com/users/php/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php/php-src","description":"The PHP Interpreter","fork":false,"url":"https://api.github.com/repos/php/php-src","forks_url":"https://api.github.com/repos/php/php-src/forks","keys_url":"https://api.github.com/repos/php/php-src/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php/php-src/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php/php-src/teams","hooks_url":"https://api.github.com/repos/php/php-src/hooks","issue_events_url":"https://api.github.com/repos/php/php-src/issues/events{/number}","events_url":"https://api.github.com/repos/php/php-src/events","assignees_url":"https://api.github.com/repos/php/php-src/assignees{/user}","branches_url":"https://api.github.com/repos/php/php-src/branches{/branch}","tags_url":"https://api.github.com/repos/php/php-src/tags","blobs_url":"https://api.github.com/repos/php/php-src/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php/php-src/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php/php-src/git/refs{/sha}","trees_url":"https://api.github.com/repos/php/php-src/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php/php-src/statuses/{sha}","languages_url":"https://api.github.com/repos/php/php-src/languages","stargazers_url":"https://api.github.com/repos/php/php-src/stargazers","contributors_url":"https://api.github.com/repos/php/php-src/contributors","subscribers_url":"https://api.github.com/repos/php/php-src/subscribers","subscription_url":"https://api.github.com/repos/php/php-src/subscription","commits_url":"https://api.github.com/repos/php/php-src/commits{/sha}","git_commits_url":"https://api.github.com/repos/php/php-src/git/commits{/sha}","comments_url":"https://api.github.com/repos/php/php-src/comments{/number}","issue_comment_url":"https://api.github.com/repos/php/php-src/issues/comments{/number}","contents_url":"https://api.github.com/repos/php/php-src/contents/{+path}","compare_url":"https://api.github.com/repos/php/php-src/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php/php-src/merges","archive_url":"https://api.github.com/repos/php/php-src/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php/php-src/downloads","issues_url":"https://api.github.com/repos/php/php-src/issues{/number}","pulls_url":"https://api.github.com/repos/php/php-src/pulls{/number}","milestones_url":"https://api.github.com/repos/php/php-src/milestones{/number}","notifications_url":"https://api.github.com/repos/php/php-src/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php/php-src/labels{/name}","releases_url":"https://api.github.com/repos/php/php-src/releases{/id}","created_at":"2011-06-16T01:52:25Z","updated_at":"2015-02-25T08:58:51Z","pushed_at":"2015-02-25T07:40:09Z","git_url":"git://github.com/php/php-src.git","ssh_url":"git@github.com:php/php-src.git","clone_url":"https://github.com/php/php-src.git","svn_url":"https://github.com/php/php-src","homepage":"http://www.php.net","size":1302727,"stargazers_count":5412,"watchers_count":5412,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1931,"mirror_url":null,"open_issues_count":182,"forks":1931,"open_issues":182,"watchers":5412,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/php/php-src/pulls/1119"},"html":{"href":"https://github.com/php/php-src/pull/1119"},"issue":{"href":"https://api.github.com/repos/php/php-src/issues/1119"},"comments":{"href":"https://api.github.com/repos/php/php-src/issues/1119/comments"},"review_comments":{"href":"https://api.github.com/repos/php/php-src/pulls/1119/comments"},"review_comment":{"href":"https://api.github.com/repos/php/php-src/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/php/php-src/pulls/1119/commits"},"statuses":{"href":"https://api.github.com/repos/php/php-src/statuses/c6fc3915c450a94ffeec40d66b720f80598299f0"}}}}