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
01b791a9
Commit
01b791a9
authored
Feb 02, 2017
by
Stéphane Graber
Committed by
GitHub
Feb 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1410 from brauner/2017-02-02/fix_compiler_error
conf/ile: make sure buffer is large enough
parents
9338493e
091045f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
44 deletions
+68
-44
conf.c
src/lxc/conf.c
+40
-27
confile.c
src/lxc/confile.c
+27
-16
utils.c
src/lxc/utils.c
+1
-1
No files found.
src/lxc/conf.c
View file @
01b791a9
...
...
@@ -3058,20 +3058,21 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
int
bytes
,
pipefd
[
2
];
char
*
token
,
*
saveptr
=
NULL
;
char
buffer
[
MAX_BUFFER_SIZE
];
char
netdev_link
[
IFNAMSIZ
+
1
];
char
netdev_link
[
IFNAMSIZ
+
1
];
if
(
netdev
->
type
!=
LXC_NET_VETH
)
{
ERROR
(
"nic type %d not support for unprivileged use"
,
netdev
->
type
);
netdev
->
type
);
return
-
1
;
}
if
(
pipe
(
pipefd
)
<
0
)
{
if
(
pipe
(
pipefd
)
<
0
)
{
SYSERROR
(
"pipe failed"
);
return
-
1
;
}
if
((
child
=
fork
())
<
0
)
{
child
=
fork
();
if
(
child
<
0
)
{
SYSERROR
(
"fork"
);
close
(
pipefd
[
0
]);
close
(
pipefd
[
1
]);
...
...
@@ -3079,35 +3080,45 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
}
if
(
child
==
0
)
{
// child
/* close the read-end of the pipe */
close
(
pipefd
[
0
]);
/* redirect the stdout to write-end of the pipe */
dup2
(
pipefd
[
1
],
STDOUT_FILENO
);
/* close the write-end of the pipe */
close
(
pipefd
[
1
]);
/* Call lxc-user-nic pid type bridge. */
int
ret
;
char
pidstr
[
LXC_NUMSTRLEN64
];
close
(
pipefd
[
0
]);
/* Close the read-end of the pipe. */
/* Redirect stdout to write-end of the pipe. */
ret
=
dup2
(
pipefd
[
1
],
STDOUT_FILENO
);
close
(
pipefd
[
1
]);
/* Close the write-end of the pipe. */
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to dup2() to redirect stdout to pipe file descriptor."
);
exit
(
EXIT_FAILURE
);
}
// Call lxc-user-nic pid type bridge
char
pidstr
[
20
];
if
(
netdev
->
link
)
{
if
(
netdev
->
link
)
strncpy
(
netdev_link
,
netdev
->
link
,
IFNAMSIZ
);
}
else
{
else
strncpy
(
netdev_link
,
"none"
,
IFNAMSIZ
);
}
snprintf
(
pidstr
,
19
,
"%lu"
,
(
unsigned
long
)
pid
);
pidstr
[
19
]
=
'\0'
;
ret
=
snprintf
(
pidstr
,
LXC_NUMSTRLEN64
,
"%d"
,
pid
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
pidstr
[
LXC_NUMSTRLEN64
-
1
]
=
'\0'
;
INFO
(
"Execing lxc-user-nic %s %s %s veth %s %s"
,
lxcpath
,
lxcname
,
pidstr
,
netdev_link
,
netdev
->
name
);
execlp
(
LXC_USERNIC_PATH
,
LXC_USERNIC_PATH
,
lxcpath
,
lxcname
,
pidstr
,
"veth"
,
netdev_link
,
netdev
->
name
,
NULL
);
SYSERROR
(
"execvp lxc-user-nic"
);
exit
(
1
);
pidstr
,
"veth"
,
netdev_link
,
netdev
->
name
,
NULL
);
SYSERROR
(
"Failed to exec lxc-user-nic."
);
exit
(
EXIT_FAILURE
);
}
/* close the write-end of the pipe */
close
(
pipefd
[
1
]);
bytes
=
read
(
pipefd
[
0
],
&
buffer
,
MAX_BUFFER_SIZE
);
if
(
bytes
<
0
)
{
SYSERROR
(
"read failed"
);
}
if
(
bytes
<
0
)
SYSERROR
(
"Failed to read from pipe file descriptor."
);
buffer
[
bytes
-
1
]
=
'\0'
;
if
(
wait_for_pid
(
child
)
!=
0
)
{
...
...
@@ -3122,21 +3133,23 @@ static int unpriv_assign_nic(const char *lxcpath, char *lxcname,
token
=
strtok_r
(
buffer
,
":"
,
&
saveptr
);
if
(
!
token
)
return
-
1
;
netdev
->
name
=
malloc
(
IFNAMSIZ
+
1
);
netdev
->
name
=
malloc
(
IFNAMSIZ
+
1
);
if
(
!
netdev
->
name
)
{
ERROR
(
"Out of memory
"
);
SYSERROR
(
"Failed to allocate memory.
"
);
return
-
1
;
}
memset
(
netdev
->
name
,
0
,
IFNAMSIZ
+
1
);
memset
(
netdev
->
name
,
0
,
IFNAMSIZ
+
1
);
strncpy
(
netdev
->
name
,
token
,
IFNAMSIZ
);
/* fill netdev->veth_attr.pair field */
token
=
strtok_r
(
NULL
,
":"
,
&
saveptr
);
if
(
!
token
)
return
-
1
;
netdev
->
priv
.
veth_attr
.
pair
=
strdup
(
token
);
if
(
!
netdev
->
priv
.
veth_attr
.
pair
)
{
ERROR
(
"
Out of memory
"
);
ERROR
(
"
Failed to allocate memory.
"
);
return
-
1
;
}
...
...
src/lxc/confile.c
View file @
01b791a9
...
...
@@ -725,7 +725,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf)
freeifaddrs
(
ifaddr
);
/* free the dynamic memory */
ifaddr
=
NULL
;
/* prevent use after free */
return
ret
;
}
...
...
@@ -2957,21 +2957,21 @@ next:
} \
}
static
void
new_hwaddr
(
char
*
hwaddr
)
static
bool
new_hwaddr
(
char
*
hwaddr
)
{
FILE
*
f
;
f
=
fopen
(
"/dev/urandom"
,
"r"
);
if
(
f
)
{
unsigned
int
seed
;
int
ret
=
fread
(
&
seed
,
sizeof
(
seed
),
1
,
f
);
if
(
ret
!=
1
)
seed
=
time
(
NULL
);
fclose
(
f
);
srand
(
seed
);
}
else
srand
(
time
(
NULL
));
snprintf
(
hwaddr
,
18
,
"00:16:3e:%02x:%02x:%02x"
,
rand
()
%
255
,
rand
()
%
255
,
rand
()
%
255
)
;
int
ret
;
/* COMMENT(brauner): Initialize random number generator. */
(
void
)
randseed
(
true
)
;
ret
=
snprintf
(
hwaddr
,
18
,
"00:16:3e:%02x:%02x:%02x"
,
rand
()
%
255
,
rand
()
%
255
,
rand
()
%
255
);
if
(
ret
<
0
||
ret
>=
18
)
{
SYSERROR
(
"Failed to call snprintf()."
);
return
false
;
}
return
true
;
}
/*
...
...
@@ -2993,27 +2993,33 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
if
(
!
conf
->
unexpanded_config
)
return
true
;
while
(
*
lstart
)
{
char
newhwaddr
[
18
],
oldhwaddr
[
17
];
lend
=
strchr
(
lstart
,
'\n'
);
if
(
!
lend
)
lend
=
lstart
+
strlen
(
lstart
);
else
lend
++
;
if
(
strncmp
(
lstart
,
key
,
strlen
(
key
))
!=
0
)
{
lstart
=
lend
;
continue
;
}
p
=
strchr
(
lstart
+
strlen
(
key
),
'='
);
if
(
!
p
)
{
lstart
=
lend
;
continue
;
}
p
++
;
while
(
isblank
(
*
p
))
p
++
;
if
(
!*
p
)
return
true
;
p2
=
p
;
while
(
*
p2
&&
!
isblank
(
*
p2
)
&&
*
p2
!=
'\n'
)
p2
++
;
...
...
@@ -3022,8 +3028,12 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
lstart
=
lend
;
continue
;
}
memcpy
(
oldhwaddr
,
p
,
17
);
new_hwaddr
(
newhwaddr
);
if
(
!
new_hwaddr
(
newhwaddr
))
return
false
;
memcpy
(
p
,
newhwaddr
,
17
);
lxc_list_for_each
(
it
,
&
conf
->
network
)
{
struct
lxc_netdev
*
n
=
it
->
elem
;
...
...
@@ -3033,6 +3043,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
lstart
=
lend
;
}
return
true
;
}
...
...
src/lxc/utils.c
View file @
01b791a9
...
...
@@ -1014,7 +1014,7 @@ int randseed(bool srand_it)
/*
srand pre-seed function based on /dev/urandom
*/
unsigned
int
seed
=
time
(
NULL
)
+
getpid
();
unsigned
int
seed
=
time
(
NULL
)
+
getpid
();
FILE
*
f
;
f
=
fopen
(
"/dev/urandom"
,
"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