Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b27df6fa
Kaydet (Commit)
b27df6fa
authored
Ock 06, 2017
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #29157: enhance py_getrandom() documentation
üst
de2f1ea1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
random.c
Python/random.c
+20
-13
No files found.
Python/random.c
Dosyayı görüntüle @
b27df6fa
...
...
@@ -82,14 +82,18 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
#if defined(HAVE_GETRANDOM) || defined(HAVE_GETRANDOM_SYSCALL)
#define PY_GETRANDOM 1
/* Call getrandom()
/* Call getrandom() to get random bytes:
- Return 1 on success
- Return 0 if getrandom()
syscall is not available (failed with ENOSYS or
EPERM) or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom
not
initialized yet) and raise=0.
- Return 0 if getrandom()
is not available (failed with ENOSYS or EPERM),
or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom not
initialized yet) and raise=0.
- Raise an exception (if raise is non-zero) and return -1 on error:
getrandom() failed with EINTR and the Python signal handler raised an
exception, or getrandom() failed with a different error. */
if getrandom() failed with EINTR, raise is non-zero and the Python signal
handler raised an exception, or if getrandom() failed with a different
error.
getrandom() is retried if it failed with EINTR: interrupted by a signal. */
static
int
py_getrandom
(
void
*
buffer
,
Py_ssize_t
size
,
int
blocking
,
int
raise
)
{
...
...
@@ -110,7 +114,8 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
while
(
0
<
size
)
{
#ifdef sun
/* Issue #26735: On Solaris, getrandom() is limited to returning up
to 1024 bytes */
to 1024 bytes. Call it multiple times if more bytes are
requested. */
n
=
Py_MIN
(
size
,
1024
);
#else
n
=
Py_MIN
(
size
,
LONG_MAX
);
...
...
@@ -141,18 +146,19 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
#endif
if
(
n
<
0
)
{
/* ENOSYS:
getrandom() syscall not supported by the kernel (but
* maybe supported by the host which built Python). EPERM:
* getrandom() syscall blocked by SECCOMP
or something else. */
/* ENOSYS:
the syscall is not supported by the kernel.
EPERM: the syscall is blocked by a security policy (ex: SECCOMP)
or something else. */
if
(
errno
==
ENOSYS
||
errno
==
EPERM
)
{
getrandom_works
=
0
;
return
0
;
}
/* getrandom(GRND_NONBLOCK) fails with EAGAIN if the system urandom
is not initialiazed yet. For _PyRandom_Init(), we ignore the
ir
is not initialiazed yet. For _PyRandom_Init(), we ignore the
error and fall back on reading /dev/urandom which never blocks,
even if the system urandom is not initialized yet. */
even if the system urandom is not initialized yet:
see the PEP 524. */
if
(
errno
==
EAGAIN
&&
!
raise
&&
!
blocking
)
{
return
0
;
}
...
...
@@ -313,9 +319,10 @@ dev_urandom(char *buffer, Py_ssize_t size, int raise)
fd
=
_Py_open
(
"/dev/urandom"
,
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
errno
==
ENOENT
||
errno
==
ENXIO
||
errno
==
ENODEV
||
errno
==
EACCES
)
errno
==
ENODEV
||
errno
==
EACCES
)
{
PyErr_SetString
(
PyExc_NotImplementedError
,
"/dev/urandom (or equivalent) not found"
);
}
/* otherwise, keep the OSError exception raised by _Py_open() */
return
-
1
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment