Skip to content

Commit

Permalink
activation: Fix wrong argument check of plist_strip_xml()
Browse files Browse the repository at this point in the history
This also fixes a potential segfault when xmlplist is NULL and adds
check for failing to allocate memory.
  • Loading branch information
zbalaton committed Jul 14, 2017
1 parent a671665 commit 260eec0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/activation.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,22 +610,23 @@ static int plist_strip_xml(char** xmlplist)
{
uint32_t size = 0;

if (!xmlplist && !*xmlplist)
if (!xmlplist || !*xmlplist)
return -1;

char* start = strstr(*xmlplist, "<plist version=\"1.0\">\n");
if (start == NULL) {
if (!start)
return -1;
}

char* stop = strstr(*xmlplist, "\n</plist>");
if (stop == NULL) {
if (!stop)
return -1;
}

start += strlen("<plist version=\"1.0\">\n");
size = stop - start;
char* stripped = malloc(size + 1);
if (!stripped)
return -1;

memset(stripped, '\0', size + 1);
memcpy(stripped, start, size);
free(*xmlplist);
Expand Down

0 comments on commit 260eec0

Please sign in to comment.