Commit Graph

48 Commits

Author SHA1 Message Date
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
David CARLIER
7a049cd6a4 Use arc4random_buf on macOS
macOS uses an AES based arc4random_buf implementation since at least
macOS 10.2.

Closes GH-6591.
2021-01-12 10:42:09 +01:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Máté Kocsis
bb6f374048
Improve argument error messages in ext/standard
Closes GH-5198
2020-03-18 19:56:10 +01:00
Máté Kocsis
aadd3aaed9
Use RETURN_THROWS() in various places 2020-01-03 21:10:24 +01:00
Máté Kocsis
01a50778d1
Use RETURN_THROWS() after zend_throw_exception() in most of the extensions 2020-01-02 10:56:18 +01:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Nikita Popov
9d4a9ad0c7 Merge branch 'PHP-7.4' 2019-09-03 12:28:35 +02:00
Nikita Popov
265af40a0a Use unsigned subtraction in php_random_int()
This subtraction may overflow the signed domain, which is UB. Use
an unsigned subtraction instead.
2019-09-03 12:28:18 +02:00
Nikita Popov
8fc58a1a1d Merge branch 'PHP-7.4' 2019-07-01 11:14:54 +02:00
Nikita Popov
7e6db70064 Msan: Unpoison getrandom() syscall result 2019-07-01 11:14:17 +02:00
Nikita Popov
513b76794b Make zpp failures always throw, independent of strict_types
Previously zend_parse_parameters (and FastZPP) would handle invalid
arguments depending on strict_types: With strict_types=1, a TypeError
is thrown, with strict_types=0 a warning is thrown and (usually) NULL
is returned. Additionally, some functions (constructors always and
other methods sometimes) opt-it to throwing regardless of strict_types.

This commit changes zpp to always generate a TypeError exception in
PHP 8.
2019-03-11 11:32:20 +01:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00
Zeev Suraski
0cf7de1c70 Remove yearly range from copyright notice 2019-01-30 11:03:12 +02:00
Peter Kokot
8d3f8ca12a Remove unused Git attributes ident
The $Id$ keywords were used in Subversion where they can be substituted
with filename, last revision number change, last changed date, and last
user who changed it.

In Git this functionality is different and can be done with Git attribute
ident. These need to be defined manually for each file in the
.gitattributes file and are afterwards replaced with 40-character
hexadecimal blob object name which is based only on the particular file
contents.

This patch simplifies handling of $Id$ keywords by removing them since
they are not used anymore.
2018-07-25 00:53:25 +02:00
Anatol Belski
1870a61a91 Fix coding style 2018-07-06 17:57:08 +02:00
David Carlier
9da4e30c75 random_bytes improvements for FreeBSD (from 12.x serie)
giving the possiblity to pre-fill the buffer. A new getrandom
function was added for future version with a similar interface
than Linux's syscall.
2018-07-06 17:47:59 +02:00
Dmitry Stogov
5eb1f92f31 Use zend_string_release_ex() instread of zend_string_release() in places, where we sure about string persistence. 2018-05-28 16:27:12 +03:00
Xinchen Hui
a6519d0514 year++ 2018-01-02 12:57:58 +08:00
krakjoe
1362c849e8
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1:
  Fix bug #75409
2017-11-22 04:32:42 +00:00
Scott
269d160159
Fix bug #75409 2017-11-22 04:26:54 +00:00
Xinchen Hui
696bd37e67 Merge branch 'PHP-7.1'
* PHP-7.1:
  Fixed condition check
  Fixed condition check
  another place

Conflicts:
	ext/mcrypt/mcrypt.c
2017-04-10 14:49:13 +08:00
Xinchen Hui
4bebcb84ad Fixed condition check 2017-04-10 14:47:24 +08:00
Nikita Popov
5da004cc75 Merge branch 'PHP-7.1' 2017-02-17 18:44:10 +01:00
Benjamin Robin
513582814b Fixed bug #74105
If getrandom syscall is unavailable (ENOSYS), try to fallback on
/dev/urandom.
2017-02-17 18:42:35 +01:00
Nikita Popov
2aaf57e6ed Merge branch 'PHP-7.1' 2017-01-09 23:30:07 +01:00
Leigh
14c72cc582 Fix check for linux getrandom syscall 2017-01-09 23:29:07 +01:00
Sammy Kaye Powers
478f119ab9 Update copyright headers to 2017 2017-01-04 11:14:55 -06:00
Sammy Kaye Powers
9e29f841ce Update copyright headers to 2017 2017-01-02 09:30:12 -06:00
Sara Golemon
6f3945a9f1 Use new param API in standard 2016-12-30 12:56:21 -08:00
Leigh
c3361f16c7 Add php_random_int internal API
This is the internal API compliment to `php_random_bytes`
2016-10-20 10:18:07 +01:00
Lior Kaplan
2eb1f38d24 Happy new year (Update copyright to 2016) 2016-01-01 20:03:16 +02:00
Scott
c0ce2281bc Update random.c
Supersedes #1589
2015-12-08 13:16:48 +01:00
Anthony Ferrara
908f67b1d4 Expose php_random_bytes as a first-class API within internals
This also defines two macros: php_random_bytes_throw and php_random_bytes_silent depending on use case which will throw exceptions or not respectively
2015-12-08 13:12:45 +01:00
Scott
00e3b7614e Update random.c
Ref: beb826f6fd
2015-12-01 10:33:33 +08:00
Leigh
faf835be2b Use arc4random on OpenBSD 5.5+ and NetBSD 7+
As discussed with @weltling, keeping arc4random on the condition that the OS has a solid implementation of it
2015-10-30 19:08:20 +00:00
Leigh
a53510239f Remove arc4random
There has been a lot of discussion around whether arc4random should be included. Given how many different impementations of it are in the wild, we can't guarantee a secure implementation on all platforms.
2015-10-26 20:40:28 +00:00
Scott
63617a678f Fixed bug #70641 (Random_* - Better compatibility on Linux distros)
See:
* https://bugs.php.net/bug.php?id=70641
* https://github.com/php/php-src/pull/1513#issuecomment-145571829
2015-10-06 01:03:04 +02:00
Scott
694b9af5b6 Remove makedev() check. 2015-09-29 09:14:30 +02:00
Scott
46aa628605 Different error message if makedev check fails 2015-09-29 09:14:29 +02:00
Scott
6554f721f7 Add support for getrandom(2), add type check on file descriptor
Fix to_read, throw exception if syscall fails

Fixes thanks to feedback from sarnold at ##crypto on freenode

Correction on error conditions

Remove dead code (thanks @defuse)

It turns out getrandom can take >256, getentropy refuses.

Better semantics

Thanks @defuse for catching my silly mistake here

Cast to size_t to be explicit

Let's simplify the logic a bit

Let's be consistent; define everything before we do any logic

Continuously check that the file descriptor is still a valid one

Add device type check on fd initialization
2015-09-29 09:14:28 +02:00
Bob Weinand
c12917aa45 Merged RFC Random Functions Throwing Exceptions in PHP 7
Squashes commits from PR #1397

commit cd5dcc8c9eb43603d908abcea69c9e18df0f2ed5
Author: SammyK <sammyk@sammykmedia.com>
Date:   Tue Sep 8 13:53:42 2015 -0500

    Add min max samezies

commit b719499218a4e84efecd4dc1d4235d16142c9793
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 07:00:25 2015 -0500

    Make random_bytes() throw Error when $length <= 0 and random_int() throw Error when $min > $max

commit 0cca557291c278716ec4b00b32fc2bdc1c1c8848
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 06:55:59 2015 -0500

    Make random_*() functions throw Error exception when random bytes cannot be obtained

commit 998c7f1e209123605b41139e8d9093075ce16bd6
Author: SammyK <sammyk@sammykmedia.com>
Date:   Wed Sep 2 06:41:20 2015 -0500

    Make random_*() functions throw TypeError when zend_parse_parameters fails

commit 99d305c18820ff55d82d952777cbcdf1cf0158be
Author: SammyK <sammyk@sammykmedia.com>
Date:   Mon Jul 6 19:50:47 2015 -0500

    Make exceptions less specific

commit b042dfab290713366741a663a420cf12bf802f39
Author: SammyK <sammyk@sammykmedia.com>
Date:   Mon Jul 6 17:20:13 2015 -0500

    Upgrade warnings to RuntimeExceptions
2015-09-09 01:00:29 +02:00
Anatol Belski
cbcacbb2da improve condition
read() == 0 is EOL
2015-08-12 10:20:26 +02:00
Dmitry Stogov
4a2e40bb86 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 04:05:24 +03:00
Lauri Kenttä
cf7e5357a4 random_int: Fix power of two check.
(x & ~x) is always 0.
((x & (~x + 1)) != x) works.
((x & (x - 1)) != 0) works too.
2015-05-10 13:00:45 +02:00
SammyK
dd2692621d Add tests for CSPRNG, fix C99 comments
Also replace one return; with RETURN_FALSE; for consistency.
2015-05-09 22:29:26 +02:00
Leigh
5f1b83e9bb Improve CSPRNG implementation 2015-05-09 21:57:59 +02:00
SammyK
bc54d139aa Initial implementation for CSPRNG API 2015-05-09 21:57:50 +02:00