Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libplist
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
pwn
libplist
Commits
35fdf8e7
Commit
35fdf8e7
authored
8 years ago
by
Nikias Bassen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xplist: Prevent memory leaks when parsing fails
parent
c98451f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
37 deletions
+20
-37
xplist.c
src/xplist.c
+20
-37
No files found.
src/xplist.c
View file @
35fdf8e7
...
@@ -944,9 +944,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -944,9 +944,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
if
(
!
tp
)
{
if
(
!
tp
)
{
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
free
(
tag
);
ctx
->
err
++
;
free
(
keyname
);
goto
err_out
;
break
;
}
}
if
(
tp
->
begin
)
{
if
(
tp
->
begin
)
{
int
requires_free
=
0
;
int
requires_free
=
0
;
...
@@ -955,9 +954,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -955,9 +954,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
break
;
}
}
char
*
str
=
str_content
;
char
*
str
=
str_content
;
int
is_negative
=
0
;
int
is_negative
=
0
;
...
@@ -998,9 +995,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -998,9 +995,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
if
(
!
tp
)
{
if
(
!
tp
)
{
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
free
(
tag
);
ctx
->
err
++
;
free
(
keyname
);
goto
err_out
;
break
;
}
}
if
(
tp
->
begin
)
{
if
(
tp
->
begin
)
{
int
requires_free
=
0
;
int
requires_free
=
0
;
...
@@ -1009,9 +1005,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1009,9 +1005,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
break
;
}
}
data
->
realval
=
atof
(
str_content
);
data
->
realval
=
atof
(
str_content
);
if
(
requires_free
)
{
if
(
requires_free
)
{
...
@@ -1045,18 +1039,15 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1045,18 +1039,15 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
if
(
!
tp
)
{
if
(
!
tp
)
{
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
free
(
tag
);
ctx
->
err
++
;
free
(
keyname
);
goto
err_out
;
break
;
}
}
str
=
text_parts_get_content
(
tp
,
1
,
&
length
,
NULL
);
str
=
text_parts_get_content
(
tp
,
1
,
&
length
,
NULL
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
if
(
!
str
)
{
if
(
!
str
)
{
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
return
;
}
}
if
(
!
strcmp
(
tag
,
"key"
)
&&
!
keyname
&&
*
plist
&&
(
plist_get_node_type
(
*
plist
)
==
PLIST_DICT
))
{
if
(
!
strcmp
(
tag
,
"key"
)
&&
!
keyname
&&
*
plist
&&
(
plist_get_node_type
(
*
plist
)
==
PLIST_DICT
))
{
keyname
=
str
;
keyname
=
str
;
...
@@ -1080,9 +1071,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1080,9 +1071,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
if
(
!
tp
)
{
if
(
!
tp
)
{
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
free
(
tag
);
ctx
->
err
++
;
free
(
keyname
);
goto
err_out
;
break
;
}
}
if
(
tp
->
begin
)
{
if
(
tp
->
begin
)
{
int
requires_free
=
0
;
int
requires_free
=
0
;
...
@@ -1091,9 +1081,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1091,9 +1081,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
break
;
}
}
size_t
size
=
tp
->
length
;
size_t
size
=
tp
->
length
;
data
->
buff
=
base64decode
(
str_content
,
&
size
);
data
->
buff
=
base64decode
(
str_content
,
&
size
);
...
@@ -1113,9 +1101,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1113,9 +1101,8 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
if
(
!
tp
)
{
if
(
!
tp
)
{
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not parse text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
free
(
tag
);
ctx
->
err
++
;
free
(
keyname
);
goto
err_out
;
break
;
}
}
Time64_T
timev
=
0
;
Time64_T
timev
=
0
;
if
(
tp
->
begin
)
{
if
(
tp
->
begin
)
{
...
@@ -1126,9 +1113,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1126,9 +1113,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
PLIST_XML_ERR
(
"Could not get text content for '%s' node
\n
"
,
tag
);
text_parts_free
(
first_part
.
next
);
text_parts_free
(
first_part
.
next
);
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
break
;
}
}
if
((
length
>=
11
)
&&
(
length
<
32
))
{
if
((
length
>=
11
)
&&
(
length
<
32
))
{
...
@@ -1157,9 +1142,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1157,9 +1142,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
PLIST_XML_ERR
(
"Unexpected tag <%s%s> encountered
\n
"
,
tag
,
(
is_empty
)
?
"/"
:
""
);
PLIST_XML_ERR
(
"Unexpected tag <%s%s> encountered
\n
"
,
tag
,
(
is_empty
)
?
"/"
:
""
);
ctx
->
pos
=
ctx
->
end
;
ctx
->
pos
=
ctx
->
end
;
ctx
->
err
++
;
ctx
->
err
++
;
free
(
tag
);
goto
err_out
;
free
(
keyname
);
return
;
}
}
if
(
subnode
&&
!
closing_tag
)
{
if
(
subnode
&&
!
closing_tag
)
{
/* parse sub nodes for structured types */
/* parse sub nodes for structured types */
...
@@ -1169,9 +1152,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1169,9 +1152,7 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
node_from_xml
(
ctx
,
&
subnode
,
depth
+
1
);
node_from_xml
(
ctx
,
&
subnode
,
depth
+
1
);
if
(
ctx
->
err
)
{
if
(
ctx
->
err
)
{
/* make sure to bail out if parsing failed */
/* make sure to bail out if parsing failed */
free
(
tag
);
goto
err_out
;
free
(
keyname
);
return
;
}
}
if
((
data
->
type
==
PLIST_DICT
)
&&
(
plist_dict_get_size
(
subnode
)
==
1
))
{
if
((
data
->
type
==
PLIST_DICT
)
&&
(
plist_dict_get_size
(
subnode
)
==
1
))
{
/* convert XML CF$UID dictionaries to PLIST_UID nodes */
/* convert XML CF$UID dictionaries to PLIST_UID nodes */
...
@@ -1239,11 +1220,13 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
...
@@ -1239,11 +1220,13 @@ static void node_from_xml(parse_ctx ctx, plist_t *plist, uint32_t depth)
break
;
break
;
}
}
}
}
err_out:
free
(
tag
);
free
(
tag
);
free
(
keyname
);
free
(
keyname
);
keyname
=
NULL
;
keyname
=
NULL
;
plist_free
(
subnode
);
plist_free
(
subnode
);
if
(
closing_tag
)
{
subnode
=
NULL
;
if
(
closing_tag
||
ctx
->
err
)
{
break
;
break
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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