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
aef295c2
Unverified
Commit
aef295c2
authored
Jun 14, 2018
by
Christian Brauner
Committed by
GitHub
Jun 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2401 from 2xsec/bugfix
fix getgrgid() thread safe issue
parents
7d910064
3de9fb4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
11 deletions
+56
-11
lxc_user_nic.c
src/lxc/cmd/lxc_user_nic.c
+30
-7
conf.c
src/lxc/conf.c
+26
-4
No files found.
src/lxc/cmd/lxc_user_nic.c
View file @
aef295c2
...
@@ -153,7 +153,10 @@ static char **get_groupnames(void)
...
@@ -153,7 +153,10 @@ static char **get_groupnames(void)
gid_t
*
group_ids
;
gid_t
*
group_ids
;
int
ret
,
i
;
int
ret
,
i
;
char
**
groupnames
;
char
**
groupnames
;
struct
group
*
gr
;
struct
group
grent
;
struct
group
*
grentp
=
NULL
;
char
*
buf
;
size_t
bufsize
;
ngroups
=
getgroups
(
0
,
NULL
);
ngroups
=
getgroups
(
0
,
NULL
);
if
(
ngroups
<
0
)
{
if
(
ngroups
<
0
)
{
...
@@ -189,28 +192,48 @@ static char **get_groupnames(void)
...
@@ -189,28 +192,48 @@ static char **get_groupnames(void)
return
NULL
;
return
NULL
;
}
}
bufsize
=
sysconf
(
_SC_GETGR_R_SIZE_MAX
);
if
(
bufsize
==
-
1
)
bufsize
=
1024
;
buf
=
malloc
(
bufsize
);
if
(
!
buf
)
{
free
(
group_ids
);
free_groupnames
(
groupnames
);
usernic_error
(
"Failed to allocate memory while getting group "
"names: %s
\n
"
,
strerror
(
errno
));
return
NULL
;
}
memset
(
groupnames
,
0
,
sizeof
(
char
*
)
*
(
ngroups
+
1
));
memset
(
groupnames
,
0
,
sizeof
(
char
*
)
*
(
ngroups
+
1
));
for
(
i
=
0
;
i
<
ngroups
;
i
++
)
{
for
(
i
=
0
;
i
<
ngroups
;
i
++
)
{
gr
=
getgrgid
(
group_ids
[
i
]);
ret
=
getgrgid_r
(
group_ids
[
i
],
&
grent
,
buf
,
bufsize
,
&
grentp
);
if
(
!
gr
)
{
if
(
!
grentp
)
{
usernic_error
(
"Failed to get group name: %s
\n
"
,
if
(
ret
==
0
)
strerror
(
errno
));
usernic_error
(
"%s"
,
"Could not find matched group record
\n
"
);
usernic_error
(
"Failed to get group name: %s(%u)
\n
"
,
strerror
(
errno
),
group_ids
[
i
]);
free
(
buf
);
free
(
group_ids
);
free
(
group_ids
);
free_groupnames
(
groupnames
);
free_groupnames
(
groupnames
);
return
NULL
;
return
NULL
;
}
}
groupnames
[
i
]
=
strdup
(
gr
->
gr_name
);
groupnames
[
i
]
=
strdup
(
gr
ent
.
gr_name
);
if
(
!
groupnames
[
i
])
{
if
(
!
groupnames
[
i
])
{
usernic_error
(
"Failed to copy group name
\"
%s
\"
"
,
usernic_error
(
"Failed to copy group name
\"
%s
\"
"
,
gr
->
gr_name
);
grent
.
gr_name
);
free
(
buf
);
free
(
group_ids
);
free
(
group_ids
);
free_groupnames
(
groupnames
);
free_groupnames
(
groupnames
);
return
NULL
;
return
NULL
;
}
}
}
}
free
(
buf
);
free
(
group_ids
);
free
(
group_ids
);
return
groupnames
;
return
groupnames
;
...
...
src/lxc/conf.c
View file @
aef295c2
...
@@ -4542,13 +4542,35 @@ static char *getuname(void)
...
@@ -4542,13 +4542,35 @@ static char *getuname(void)
/* not thread-safe, do not use from api without first forking */
/* not thread-safe, do not use from api without first forking */
static
char
*
getgname
(
void
)
static
char
*
getgname
(
void
)
{
{
struct
group
*
result
;
struct
group
grent
;
struct
group
*
grentp
=
NULL
;
char
*
buf
;
char
*
grname
;
size_t
bufsize
;
int
ret
;
result
=
getgrgid
(
getegid
());
bufsize
=
sysconf
(
_SC_GETGR_R_SIZE_MAX
);
if
(
!
result
)
if
(
bufsize
==
-
1
)
bufsize
=
1024
;
buf
=
malloc
(
bufsize
);
if
(
!
buf
)
return
NULL
;
return
NULL
;
return
strdup
(
result
->
gr_name
);
ret
=
getgrgid_r
(
getegid
(),
&
grent
,
buf
,
bufsize
,
&
grentp
);
if
(
!
grentp
)
{
if
(
ret
==
0
)
WARN
(
"Could not find matched group record"
);
ERROR
(
"Failed to get group record - %u"
,
getegid
());
free
(
buf
);
return
NULL
;
}
grname
=
strdup
(
grent
.
gr_name
);
free
(
buf
);
return
grname
;
}
}
/* not thread-safe, do not use from api without first forking */
/* not thread-safe, do not use from api without first forking */
...
...
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