Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent3
Commits
5cb89d9a
Commit
5cb89d9a
authored
Sep 20, 2011
by
Poul-Henning Kamp
Committed by
Tollef Fog Heen
Sep 22, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't ignore the return value of the read(2) call on a random dev.
parent
f4c29c72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
7 deletions
+21
-7
srandomdev.c
lib/libvarnishcompat/srandomdev.c
+21
-7
No files found.
lib/libvarnishcompat/srandomdev.c
View file @
5cb89d9a
...
...
@@ -40,6 +40,22 @@
#include "compat/srandomdev.h"
static
int
trydev
(
const
char
*
fn
,
unsigned
long
*
seed
)
{
int
fd
;
ssize_t
sz
;
fd
=
open
(
fn
,
O_RDONLY
);
if
(
fd
<
0
)
return
(
-
1
);
sz
=
read
(
fd
,
seed
,
sizeof
*
seed
);
(
void
)
close
(
fd
);
if
(
sz
!=
sizeof
*
seed
)
return
(
-
1
);
return
(
0
);
}
void
srandomdev
(
void
)
{
...
...
@@ -47,13 +63,11 @@ srandomdev(void)
unsigned
long
seed
;
int
fd
;
if
((
fd
=
open
(
"/dev/urandom"
,
O_RDONLY
))
>=
0
||
(
fd
=
open
(
"/dev/random"
,
O_RDONLY
))
>=
0
)
{
read
(
fd
,
&
seed
,
sizeof
seed
);
close
(
fd
);
}
else
{
gettimeofday
(
&
tv
,
NULL
);
seed
=
(
getpid
()
<<
16
)
^
tv
.
tv_sec
^
tv
.
tv_usec
;
if
(
trydev
(
"/dev/urandom"
,
&
seed
))
{
if
(
trydev
(
"/dev/random"
,
&
seed
))
{
gettimeofday
(
&
tv
,
NULL
);
seed
=
(
getpid
()
<<
16
)
^
tv
.
tv_sec
^
tv
.
tv_usec
;
}
}
srandom
(
seed
);
}
...
...
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