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
02a0e184
Unverified
Commit
02a0e184
authored
Jun 15, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coverity: #1425837
String not null terminated Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
d34212ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
28 deletions
+38
-28
lxccontainer.c
src/lxc/lxccontainer.c
+38
-28
No files found.
src/lxc/lxccontainer.c
View file @
02a0e184
...
@@ -2337,58 +2337,64 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
...
@@ -2337,58 +2337,64 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
WRAP_API
(
char
**
,
lxcapi_get_interfaces
)
WRAP_API
(
char
**
,
lxcapi_get_interfaces
)
static
char
**
do_lxcapi_get_ips
(
struct
lxc_container
*
c
,
const
char
*
interface
,
const
char
*
family
,
int
scope
)
static
char
**
do_lxcapi_get_ips
(
struct
lxc_container
*
c
,
const
char
*
interface
,
const
char
*
family
,
int
scope
)
{
{
int
i
,
ret
;
pid_t
pid
;
pid_t
pid
;
int
i
,
count
=
0
,
pipefd
[
2
];
int
pipefd
[
2
];
char
**
addresses
=
NULL
;
char
address
[
INET6_ADDRSTRLEN
];
char
address
[
INET6_ADDRSTRLEN
];
int
count
=
0
;
char
**
addresses
=
NULL
;
if
(
pipe
(
pipefd
)
<
0
)
{
ret
=
pipe
(
pipefd
);
SYSERROR
(
"pipe failed"
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to create pipe"
);
return
NULL
;
return
NULL
;
}
}
pid
=
fork
();
pid
=
fork
();
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
SYSERROR
(
"
failed to fork task to get container ip
s"
);
SYSERROR
(
"
Failed to create new proces
s"
);
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
close
(
pipefd
[
1
]);
close
(
pipefd
[
1
]);
return
NULL
;
return
NULL
;
}
}
if
(
pid
==
0
)
{
/* child */
if
(
pid
==
0
)
{
int
ret
=
1
,
nbytes
;
ssize_t
nbytes
;
struct
ifaddrs
*
interfaceArray
=
NULL
,
*
tempIfAddr
=
NULL
;
char
addressOutputBuffer
[
INET6_ADDRSTRLEN
];
char
addressOutputBuffer
[
INET6_ADDRSTRLEN
];
void
*
tempAddrPtr
=
NULL
;
int
ret
=
1
;
char
*
address
=
NULL
;
char
*
address
=
NULL
;
void
*
tempAddrPtr
=
NULL
;
struct
ifaddrs
*
interfaceArray
=
NULL
,
*
tempIfAddr
=
NULL
;
/* close the read-end of the pipe */
/* close the read-end of the pipe */
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
if
(
!
enter_net_ns
(
c
))
{
if
(
!
enter_net_ns
(
c
))
{
SYSERROR
(
"
failed to enter
namespace"
);
SYSERROR
(
"
Failed to attach to network
namespace"
);
goto
out
;
goto
out
;
}
}
/* Grab the list of interfaces */
/* Grab the list of interfaces */
if
(
getifaddrs
(
&
interfaceArray
))
{
if
(
getifaddrs
(
&
interfaceArray
))
{
SYSERROR
(
"
f
ailed to get interfaces list"
);
SYSERROR
(
"
F
ailed to get interfaces list"
);
goto
out
;
goto
out
;
}
}
/* Iterate through the interfaces */
/* Iterate through the interfaces */
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
!=
NULL
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
if
(
tempIfAddr
->
ifa_addr
==
NULL
)
if
(
tempIfAddr
->
ifa_addr
==
NULL
)
continue
;
continue
;
if
(
tempIfAddr
->
ifa_addr
->
sa_family
==
AF_INET
)
{
if
(
tempIfAddr
->
ifa_addr
->
sa_family
==
AF_INET
)
{
if
(
family
&&
strcmp
(
family
,
"inet"
))
if
(
family
&&
strcmp
(
family
,
"inet"
))
continue
;
continue
;
tempAddrPtr
=
&
((
struct
sockaddr_in
*
)
tempIfAddr
->
ifa_addr
)
->
sin_addr
;
tempAddrPtr
=
&
((
struct
sockaddr_in
*
)
tempIfAddr
->
ifa_addr
)
->
sin_addr
;
}
}
else
{
else
{
if
(
family
&&
strcmp
(
family
,
"inet6"
))
if
(
family
&&
strcmp
(
family
,
"inet6"
))
continue
;
continue
;
...
@@ -2404,15 +2410,15 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
...
@@ -2404,15 +2410,15 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
continue
;
continue
;
address
=
(
char
*
)
inet_ntop
(
tempIfAddr
->
ifa_addr
->
sa_family
,
address
=
(
char
*
)
inet_ntop
(
tempIfAddr
->
ifa_addr
->
sa_family
,
tempAddrPtr
,
tempAddrPtr
,
addressOutputBuffer
,
addressOutputBuffer
,
sizeof
(
addressOutputBuffer
));
sizeof
(
addressOutputBuffer
));
if
(
!
address
)
if
(
!
address
)
continue
;
continue
;
nbytes
=
write
(
pipefd
[
1
],
address
,
INET6_ADDRSTRLEN
);
nbytes
=
lxc_write_nointr
(
pipefd
[
1
],
address
,
INET6_ADDRSTRLEN
);
if
(
nbytes
<
0
)
{
if
(
nbytes
!=
INET6_ADDRSTRLEN
)
{
ERROR
(
"write failed"
);
SYSERROR
(
"Failed to send ipv6 address
\"
%s
\"
"
,
address
);
goto
out
;
goto
out
;
}
}
count
++
;
count
++
;
...
@@ -2420,7 +2426,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
...
@@ -2420,7 +2426,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
ret
=
0
;
ret
=
0
;
out
:
out
:
if
(
interfaceArray
)
if
(
interfaceArray
)
freeifaddrs
(
interfaceArray
);
freeifaddrs
(
interfaceArray
);
/* close the write-end of the pipe, thus sending EOF to the reader */
/* close the write-end of the pipe, thus sending EOF to the reader */
...
@@ -2431,15 +2437,19 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
...
@@ -2431,15 +2437,19 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
/* close the write-end of the pipe */
/* close the write-end of the pipe */
close
(
pipefd
[
1
]);
close
(
pipefd
[
1
]);
while
(
read
(
pipefd
[
0
],
&
address
,
INET6_ADDRSTRLEN
)
==
INET6_ADDRSTRLEN
)
{
while
(
lxc_read_nointr
(
pipefd
[
0
],
&
address
,
INET6_ADDRSTRLEN
)
==
INET6_ADDRSTRLEN
)
{
if
(
!
add_to_array
(
&
addresses
,
address
,
count
))
address
[
INET6_ADDRSTRLEN
-
1
]
=
'\0'
;
if
(
!
add_to_array
(
&
addresses
,
address
,
count
))
ERROR
(
"PARENT: add_to_array failed"
);
ERROR
(
"PARENT: add_to_array failed"
);
count
++
;
count
++
;
}
}
if
(
wait_for_pid
(
pid
)
!=
0
)
{
if
(
wait_for_pid
(
pid
)
!=
0
)
{
for
(
i
=
0
;
i
<
count
;
i
++
)
for
(
i
=
0
;
i
<
count
;
i
++
)
free
(
addresses
[
i
]);
free
(
addresses
[
i
]);
free
(
addresses
);
free
(
addresses
);
addresses
=
NULL
;
addresses
=
NULL
;
}
}
...
@@ -2448,7 +2458,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
...
@@ -2448,7 +2458,7 @@ static char** do_lxcapi_get_ips(struct lxc_container *c, const char* interface,
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
/* Append NULL to the array */
/* Append NULL to the array */
if
(
addresses
)
if
(
addresses
)
addresses
=
(
char
**
)
lxc_append_null_to_array
((
void
**
)
addresses
,
count
);
addresses
=
(
char
**
)
lxc_append_null_to_array
((
void
**
)
addresses
,
count
);
return
addresses
;
return
addresses
;
...
...
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