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
2dce415b
Unverified
Commit
2dce415b
authored
Jun 12, 2018
by
Donghwa Jeong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix getpwnam() thread safe issue
Signed-off-by:
Donghwa Jeong
<
dh48.jeong@samsung.com
>
parent
c6d0d3cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
11 deletions
+51
-11
pam_cgfs.c
src/lxc/pam/pam_cgfs.c
+23
-5
lxc_unshare.c
src/lxc/tools/lxc_unshare.c
+28
-6
No files found.
src/lxc/pam/pam_cgfs.c
View file @
2dce415b
...
...
@@ -1520,14 +1520,32 @@ static void cg_escape(void)
/* Get uid and gid for @user. */
static
bool
get_uid_gid
(
const
char
*
user
,
uid_t
*
uid
,
gid_t
*
gid
)
{
struct
passwd
*
pwent
;
strcut
passwd
pwent
;
struct
passwd
*
pwentp
=
NULL
;
char
*
buf
;
size_t
bufsize
;
int
ret
;
bufsize
=
sysconf
(
_SC_GETPW_R_SIZE_MAX
);
if
(
bufsize
==
-
1
)
bufsize
=
1024
;
buf
=
malloc
(
bufsize
);
if
(
!
buf
)
return
false
;
ret
=
getpwnam_r
(
user
,
&
pwent
,
buf
,
bufsize
,
&
pwentp
);
if
(
!
pwentp
)
{
if
(
ret
==
0
)
mysyslog
(
LOG_ERR
,
"Could not find matched password record.
\n
"
,
NULL
);
pwent
=
getpwnam
(
user
);
if
(
!
pwent
)
free
(
buf
);
return
false
;
}
*
uid
=
pwent
->
pw_uid
;
*
gid
=
pwent
->
pw_gid
;
*
uid
=
pwent
.
pw_uid
;
*
gid
=
pwent
.
pw_gid
;
free
(
buf
);
return
true
;
}
...
...
src/lxc/tools/lxc_unshare.c
View file @
2dce415b
...
...
@@ -82,29 +82,51 @@ static void usage(char *cmd)
static
bool
lookup_user
(
const
char
*
optarg
,
uid_t
*
uid
)
{
char
name
[
TOOL_MAXPATHLEN
];
struct
passwd
*
pwent
=
NULL
;
struct
passwd
pwent
;
struct
passwd
*
pwentp
=
NULL
;
char
*
buf
;
size_t
bufsize
;
int
ret
;
if
(
!
optarg
||
(
optarg
[
0
]
==
'\0'
))
return
false
;
bufsize
=
sysconf
(
_SC_GETPW_R_SIZE_MAX
);
if
(
bufsize
==
-
1
)
bufsize
=
1024
;
buf
=
malloc
(
bufsize
);
if
(
!
buf
)
return
false
;
if
(
sscanf
(
optarg
,
"%u"
,
uid
)
<
1
)
{
/* not a uid -- perhaps a username */
if
(
sscanf
(
optarg
,
"%s"
,
name
)
<
1
)
return
false
;
pwent
=
getpwnam
(
name
);
if
(
!
pwent
)
{
ret
=
getpwnam_r
(
name
,
&
pwent
,
buf
,
bufsize
,
&
pwentp
);
if
(
!
pwentp
)
{
if
(
ret
==
0
)
fprintf
(
stderr
,
"could not find matched password record
\n
"
);
fprintf
(
stderr
,
"invalid username %s
\n
"
,
name
);
free
(
buf
);
return
false
;
}
*
uid
=
pwent
->
pw_uid
;
*
uid
=
pwent
.
pw_uid
;
}
else
{
pwent
=
getpwuid
(
*
uid
);
if
(
!
pwent
)
{
ret
=
getpwuid_r
(
*
uid
,
&
pwent
,
buf
,
bufsize
,
&
pwentp
);
if
(
!
pwentp
)
{
if
(
ret
==
0
)
fprintf
(
stderr
,
"could not find matched password record
\n
"
);
fprintf
(
stderr
,
"invalid uid %u
\n
"
,
*
uid
);
free
(
buf
);
return
false
;
}
}
free
(
buf
);
return
true
;
}
...
...
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