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
3de9fb4c
Unverified
Commit
3de9fb4c
authored
Jun 14, 2018
by
Donghwa Jeong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix getgrgid() thread safe issue
Signed-off-by:
Donghwa Jeong
<
dh48.jeong@samsung.com
>
parent
cb7aa5e8
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 @
3de9fb4c
...
...
@@ -153,7 +153,10 @@ static char **get_groupnames(void)
gid_t
*
group_ids
;
int
ret
,
i
;
char
**
groupnames
;
struct
group
*
gr
;
struct
group
grent
;
struct
group
*
grentp
=
NULL
;
char
*
buf
;
size_t
bufsize
;
ngroups
=
getgroups
(
0
,
NULL
);
if
(
ngroups
<
0
)
{
...
...
@@ -189,28 +192,48 @@ static char **get_groupnames(void)
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
));
for
(
i
=
0
;
i
<
ngroups
;
i
++
)
{
gr
=
getgrgid
(
group_ids
[
i
]);
if
(
!
gr
)
{
usernic_error
(
"Failed to get group name: %s
\n
"
,
strerror
(
errno
));
ret
=
getgrgid_r
(
group_ids
[
i
],
&
grent
,
buf
,
bufsize
,
&
grentp
);
if
(
!
grentp
)
{
if
(
ret
==
0
)
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_groupnames
(
groupnames
);
return
NULL
;
}
groupnames
[
i
]
=
strdup
(
gr
->
gr_name
);
groupnames
[
i
]
=
strdup
(
gr
ent
.
gr_name
);
if
(
!
groupnames
[
i
])
{
usernic_error
(
"Failed to copy group name
\"
%s
\"
"
,
gr
->
gr_name
);
grent
.
gr_name
);
free
(
buf
);
free
(
group_ids
);
free_groupnames
(
groupnames
);
return
NULL
;
}
}
free
(
buf
);
free
(
group_ids
);
return
groupnames
;
...
...
src/lxc/conf.c
View file @
3de9fb4c
...
...
@@ -4542,13 +4542,35 @@ static char *getuname(void)
/* not thread-safe, do not use from api without first forking */
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
());
if
(
!
result
)
bufsize
=
sysconf
(
_SC_GETGR_R_SIZE_MAX
);
if
(
bufsize
==
-
1
)
bufsize
=
1024
;
buf
=
malloc
(
bufsize
);
if
(
!
buf
)
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 */
...
...
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