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
304b20df
Commit
304b20df
authored
Sep 25, 2016
by
Christian Brauner
Committed by
Stéphane Graber
Oct 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: fix lxc_string_split()
Make sure we don't return uninitialized memory. Signed-off-by:
Christian Brauner
<
christian.brauner@canonical.com
>
parent
07d11275
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
utils.c
src/lxc/utils.c
+11
-4
No files found.
src/lxc/utils.c
View file @
304b20df
...
@@ -774,8 +774,8 @@ bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
...
@@ -774,8 +774,8 @@ bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
char
**
lxc_string_split
(
const
char
*
string
,
char
_sep
)
char
**
lxc_string_split
(
const
char
*
string
,
char
_sep
)
{
{
char
*
token
,
*
str
,
*
saveptr
=
NULL
;
char
*
token
,
*
str
,
*
saveptr
=
NULL
;
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
**
result
=
NULL
;
char
**
tmp
=
NULL
,
**
result
=
NULL
;
size_t
result_capacity
=
0
;
size_t
result_capacity
=
0
;
size_t
result_count
=
0
;
size_t
result_count
=
0
;
int
r
,
saved_errno
;
int
r
,
saved_errno
;
...
@@ -783,7 +783,7 @@ char **lxc_string_split(const char *string, char _sep)
...
@@ -783,7 +783,7 @@ char **lxc_string_split(const char *string, char _sep)
if
(
!
string
)
if
(
!
string
)
return
calloc
(
1
,
sizeof
(
char
*
));
return
calloc
(
1
,
sizeof
(
char
*
));
str
=
alloca
(
strlen
(
string
)
+
1
);
str
=
alloca
(
strlen
(
string
)
+
1
);
strcpy
(
str
,
string
);
strcpy
(
str
,
string
);
for
(;
(
token
=
strtok_r
(
str
,
sep
,
&
saveptr
));
str
=
NULL
)
{
for
(;
(
token
=
strtok_r
(
str
,
sep
,
&
saveptr
));
str
=
NULL
)
{
r
=
lxc_grow_array
((
void
***
)
&
result
,
&
result_capacity
,
result_count
+
1
,
16
);
r
=
lxc_grow_array
((
void
***
)
&
result
,
&
result_capacity
,
result_count
+
1
,
16
);
...
@@ -796,7 +796,14 @@ char **lxc_string_split(const char *string, char _sep)
...
@@ -796,7 +796,14 @@ char **lxc_string_split(const char *string, char _sep)
}
}
/* if we allocated too much, reduce it */
/* if we allocated too much, reduce it */
return
realloc
(
result
,
(
result_count
+
1
)
*
sizeof
(
char
*
));
tmp
=
realloc
(
result
,
(
result_count
+
1
)
*
sizeof
(
char
*
));
if
(
!
tmp
)
goto
error_out
;
result
=
tmp
;
/* Make sure we don't return uninitialized memory. */
if
(
result_count
==
0
)
*
result
=
NULL
;
return
result
;
error_out
:
error_out
:
saved_errno
=
errno
;
saved_errno
=
errno
;
lxc_free_array
((
void
**
)
result
,
free
);
lxc_free_array
((
void
**
)
result
,
free
);
...
...
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