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
358bad40
Unverified
Commit
358bad40
authored
Jun 18, 2018
by
Donghwa Jeong
Committed by
Christian Brauner
Jun 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
secure coding: #3 strcpy => strlcpy
Signed-off-by:
Donghwa Jeong
<
dh48.jeong@samsung.com
>
parent
0cd262d1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
11 deletions
+34
-11
confile.c
src/lxc/confile.c
+3
-3
confile_utils.c
src/lxc/confile_utils.c
+13
-4
confile_utils.h
src/lxc/confile_utils.h
+1
-1
attach.c
src/tests/attach.c
+6
-1
cgpath.c
src/tests/cgpath.c
+5
-1
shortlived.c
src/tests/shortlived.c
+6
-1
No files found.
src/lxc/confile.c
View file @
358bad40
...
@@ -450,7 +450,7 @@ static int set_config_net_link(const char *key, const char *value,
...
@@ -450,7 +450,7 @@ static int set_config_net_link(const char *key, const char *value,
if
(
value
[
strlen
(
value
)
-
1
]
==
'+'
&&
netdev
->
type
==
LXC_NET_PHYS
)
if
(
value
[
strlen
(
value
)
-
1
]
==
'+'
&&
netdev
->
type
==
LXC_NET_PHYS
)
ret
=
create_matched_ifnames
(
value
,
lxc_conf
,
netdev
);
ret
=
create_matched_ifnames
(
value
,
lxc_conf
,
netdev
);
else
else
ret
=
network_ifname
(
netdev
->
link
,
value
);
ret
=
network_ifname
(
netdev
->
link
,
value
,
sizeof
(
netdev
->
link
)
);
return
ret
;
return
ret
;
}
}
...
@@ -466,7 +466,7 @@ static int set_config_net_name(const char *key, const char *value,
...
@@ -466,7 +466,7 @@ static int set_config_net_name(const char *key, const char *value,
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
-
1
;
return
network_ifname
(
netdev
->
name
,
value
);
return
network_ifname
(
netdev
->
name
,
value
,
sizeof
(
netdev
->
name
)
);
}
}
static
int
set_config_net_veth_pair
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_veth_pair
(
const
char
*
key
,
const
char
*
value
,
...
@@ -480,7 +480,7 @@ static int set_config_net_veth_pair(const char *key, const char *value,
...
@@ -480,7 +480,7 @@ static int set_config_net_veth_pair(const char *key, const char *value,
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
-
1
;
return
network_ifname
(
netdev
->
priv
.
veth_attr
.
pair
,
value
);
return
network_ifname
(
netdev
->
priv
.
veth_attr
.
pair
,
value
,
sizeof
(
netdev
->
priv
.
veth_attr
.
pair
)
);
}
}
static
int
set_config_net_macvlan_mode
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_net_macvlan_mode
(
const
char
*
key
,
const
char
*
value
,
...
...
src/lxc/confile_utils.c
View file @
358bad40
...
@@ -36,6 +36,10 @@
...
@@ -36,6 +36,10 @@
#include "parse.h"
#include "parse.h"
#include "utils.h"
#include "utils.h"
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
#endif
lxc_log_define
(
lxc_confile_utils
,
lxc
);
lxc_log_define
(
lxc_confile_utils
,
lxc
);
int
parse_idmaps
(
const
char
*
idmap
,
char
*
type
,
unsigned
long
*
nsid
,
int
parse_idmaps
(
const
char
*
idmap
,
char
*
type
,
unsigned
long
*
nsid
,
...
@@ -509,14 +513,19 @@ int config_ip_prefix(struct in_addr *addr)
...
@@ -509,14 +513,19 @@ int config_ip_prefix(struct in_addr *addr)
return
0
;
return
0
;
}
}
int
network_ifname
(
char
*
valuep
,
const
char
*
value
)
int
network_ifname
(
char
*
valuep
,
const
char
*
value
,
size_t
size
)
{
{
if
(
strlen
(
value
)
>=
IFNAMSIZ
)
{
size_t
retlen
;
if
(
!
valuep
||
!
value
)
return
-
1
;
retlen
=
strlcpy
(
valuep
,
value
,
size
);
if
(
retlen
>=
size
)
{
ERROR
(
"Network devie name
\"
%s
\"
is too long (>= %zu)"
,
value
,
ERROR
(
"Network devie name
\"
%s
\"
is too long (>= %zu)"
,
value
,
(
size_t
)
IFNAMSIZ
);
size
);
}
}
strcpy
(
valuep
,
value
);
return
0
;
return
0
;
}
}
...
...
src/lxc/confile_utils.h
View file @
358bad40
...
@@ -80,7 +80,7 @@ extern int set_config_string_item_max(char **conf_item, const char *value,
...
@@ -80,7 +80,7 @@ extern int set_config_string_item_max(char **conf_item, const char *value,
size_t
max
);
size_t
max
);
extern
int
set_config_path_item
(
char
**
conf_item
,
const
char
*
value
);
extern
int
set_config_path_item
(
char
**
conf_item
,
const
char
*
value
);
extern
int
config_ip_prefix
(
struct
in_addr
*
addr
);
extern
int
config_ip_prefix
(
struct
in_addr
*
addr
);
extern
int
network_ifname
(
char
*
valuep
,
const
char
*
value
);
extern
int
network_ifname
(
char
*
valuep
,
const
char
*
value
,
size_t
size
);
extern
int
rand_complete_hwaddr
(
char
*
hwaddr
);
extern
int
rand_complete_hwaddr
(
char
*
hwaddr
);
extern
bool
lxc_config_net_hwaddr
(
const
char
*
line
);
extern
bool
lxc_config_net_hwaddr
(
const
char
*
line
);
extern
void
update_hwaddr
(
const
char
*
line
);
extern
void
update_hwaddr
(
const
char
*
line
);
...
...
src/tests/attach.c
View file @
358bad40
...
@@ -32,6 +32,10 @@
...
@@ -32,6 +32,10 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
#endif
#define TSTNAME "lxc-attach-test"
#define TSTNAME "lxc-attach-test"
#define TSTOUT(fmt, ...) do { \
#define TSTOUT(fmt, ...) do { \
fprintf(stdout, fmt, ##__VA_ARGS__); fflush(NULL); \
fprintf(stdout, fmt, ##__VA_ARGS__); fflush(NULL); \
...
@@ -399,7 +403,8 @@ int main(int argc, char *argv[])
...
@@ -399,7 +403,8 @@ int main(int argc, char *argv[])
char
template
[
sizeof
(
P_tmpdir
"/attach_XXXXXX"
)];
char
template
[
sizeof
(
P_tmpdir
"/attach_XXXXXX"
)];
int
fret
=
EXIT_FAILURE
;
int
fret
=
EXIT_FAILURE
;
strcpy
(
template
,
P_tmpdir
"/attach_XXXXXX"
);
(
void
)
strlcpy
(
template
,
P_tmpdir
"/attach_XXXXXX"
,
sizeof
(
template
));
i
=
lxc_make_tmpfile
(
template
,
false
);
i
=
lxc_make_tmpfile
(
template
,
false
);
if
(
i
<
0
)
{
if
(
i
<
0
)
{
lxc_error
(
"Failed to create temporary log file for container %s
\n
"
,
TSTNAME
);
lxc_error
(
"Failed to create temporary log file for container %s
\n
"
,
TSTNAME
);
...
...
src/tests/cgpath.c
View file @
358bad40
...
@@ -33,6 +33,10 @@
...
@@ -33,6 +33,10 @@
#include "lxc.h"
#include "lxc.h"
#include "commands.h"
#include "commands.h"
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
#endif
#define MYNAME "lxctest1"
#define MYNAME "lxctest1"
#define TSTERR(fmt, ...) do { \
#define TSTERR(fmt, ...) do { \
...
@@ -87,7 +91,7 @@ static int test_running_container(const char *lxcpath,
...
@@ -87,7 +91,7 @@ static int test_running_container(const char *lxcpath,
TSTERR
(
"cgroup_get failed"
);
TSTERR
(
"cgroup_get failed"
);
goto
err3
;
goto
err3
;
}
}
strcpy
(
value_save
,
value
);
(
void
)
strlcpy
(
value_save
,
value
,
NAME_MAX
);
ret
=
cgroup_ops
->
set
(
cgroup_ops
,
"memory.soft_limit_in_bytes"
,
"512M"
,
ret
=
cgroup_ops
->
set
(
cgroup_ops
,
"memory.soft_limit_in_bytes"
,
"512M"
,
c
->
name
,
c
->
config_path
);
c
->
name
,
c
->
config_path
);
...
...
src/tests/shortlived.c
View file @
358bad40
...
@@ -31,6 +31,10 @@
...
@@ -31,6 +31,10 @@
#include "lxctest.h"
#include "lxctest.h"
#include "utils.h"
#include "utils.h"
#ifndef HAVE_STRLCPY
#include "include/strlcpy.h"
#endif
#define MYNAME "shortlived"
#define MYNAME "shortlived"
static
int
destroy_container
(
void
)
static
int
destroy_container
(
void
)
...
@@ -103,7 +107,8 @@ int main(int argc, char *argv[])
...
@@ -103,7 +107,8 @@ int main(int argc, char *argv[])
char
template
[
sizeof
(
P_tmpdir
"/shortlived_XXXXXX"
)];
char
template
[
sizeof
(
P_tmpdir
"/shortlived_XXXXXX"
)];
int
ret
=
EXIT_FAILURE
;
int
ret
=
EXIT_FAILURE
;
strcpy
(
template
,
P_tmpdir
"/shortlived_XXXXXX"
);
(
void
)
strlcpy
(
template
,
P_tmpdir
"/shortlived_XXXXXX"
,
sizeof
(
template
));
i
=
lxc_make_tmpfile
(
template
,
false
);
i
=
lxc_make_tmpfile
(
template
,
false
);
if
(
i
<
0
)
{
if
(
i
<
0
)
{
lxc_error
(
"Failed to create temporary log file for container %s
\n
"
,
MYNAME
);
lxc_error
(
"Failed to create temporary log file for container %s
\n
"
,
MYNAME
);
...
...
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