Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
97e56798
Unverified
Commit
97e56798
authored
Jul 21, 2018
by
Christian Brauner
Committed by
GitHub
Jul 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2486 from 2xsec/bugfix
thread safe: rand() => rand_r()
parents
9005b20d
18d4ffde
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
21 deletions
+27
-21
attach.c
src/lxc/attach.c
+3
-0
confile_utils.c
src/lxc/confile_utils.c
+15
-5
network.c
src/lxc/network.c
+9
-16
No files found.
src/lxc/attach.c
View file @
97e56798
...
...
@@ -534,6 +534,9 @@ static char *lxc_attach_getpwshell(uid_t uid)
if
(
found
)
continue
;
if
(
!
line
)
continue
;
/* Trim line on the right hand side. */
for
(
i
=
strlen
(
line
);
i
>
0
&&
(
line
[
i
-
1
]
==
'\n'
||
line
[
i
-
1
]
==
'\r'
);
--
i
)
line
[
i
-
1
]
=
'\0'
;
...
...
src/lxc/confile_utils.c
View file @
97e56798
...
...
@@ -550,14 +550,15 @@ void rand_complete_hwaddr(char *hwaddr)
{
const
char
hex
[]
=
"0123456789abcdef"
;
char
*
curs
=
hwaddr
;
#ifndef HAVE_RAND_R
randseed
(
true
);
#else
#ifdef HAVE_RAND_R
unsigned
int
seed
;
seed
=
randseed
(
false
);
#else
(
void
)
randseed
(
true
);
#endif
while
(
*
curs
!=
'\0'
&&
*
curs
!=
'\n'
)
{
if
(
*
curs
==
'x'
||
*
curs
==
'X'
)
{
if
(
curs
-
hwaddr
==
1
)
{
...
...
@@ -635,13 +636,22 @@ void update_hwaddr(const char *line)
bool
new_hwaddr
(
char
*
hwaddr
)
{
int
ret
;
#ifdef HAVE_RAND_R
unsigned
int
seed
;
seed
=
randseed
(
false
);
ret
=
snprintf
(
hwaddr
,
18
,
"00:16:3e:%02x:%02x:%02x"
,
rand_r
(
&
seed
)
%
255
,
rand_r
(
&
seed
)
%
255
,
rand_r
(
&
seed
)
%
255
);
#else
(
void
)
randseed
(
true
);
ret
=
snprintf
(
hwaddr
,
18
,
"00:16:3e:%02x:%02x:%02x"
,
rand
()
%
255
,
rand
()
%
255
,
rand
()
%
255
);
#endif
if
(
ret
<
0
||
ret
>=
18
)
{
SYSERROR
(
"Failed to call snprintf()
.
"
);
SYSERROR
(
"Failed to call snprintf()"
);
return
false
;
}
...
...
src/lxc/network.c
View file @
97e56798
...
...
@@ -1965,12 +1965,18 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char
*
lxc_mkifname
(
char
*
template
)
{
int
ret
;
unsigned
int
seed
;
FILE
*
urandom
;
struct
ifaddrs
*
ifa
,
*
ifaddr
;
char
name
[
IFNAMSIZ
];
bool
exists
=
false
;
size_t
i
=
0
;
#ifdef HAVE_RAND_R
unsigned
int
seed
;
seed
=
randseed
(
false
);
#else
(
void
)
randseed
(
true
);
#endif
if
(
strlen
(
template
)
>=
IFNAMSIZ
)
return
NULL
;
...
...
@@ -1982,26 +1988,13 @@ char *lxc_mkifname(char *template)
return
NULL
;
}
/* Initialize the random number generator. */
urandom
=
fopen
(
"/dev/urandom"
,
"r"
);
if
(
urandom
!=
NULL
)
{
if
(
fread
(
&
seed
,
sizeof
(
seed
),
1
,
urandom
)
<=
0
)
seed
=
time
(
0
);
fclose
(
urandom
);
}
else
{
seed
=
time
(
0
);
}
#ifndef HAVE_RAND_R
srand
(
seed
);
#endif
/* Generate random names until we find one that doesn't exist. */
while
(
true
)
{
name
[
0
]
=
'\0'
;
(
void
)
strlcpy
(
name
,
template
,
IFNAMSIZ
);
exists
=
false
;
for
(
i
=
0
;
i
<
strlen
(
name
);
i
++
)
{
if
(
name
[
i
]
==
'X'
)
{
#ifdef HAVE_RAND_R
...
...
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