From 66375689b8cd110355656203979f5640ecf05193 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 21 Jun 2015 21:43:38 -0700 Subject: [PATCH] Prevent null dereference In each case there are scenarios where we would have dereferenced NULL. Signed-off-by: Dirk Hohndel --- file.c | 13 ++++++------- parse-xml.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/file.c b/file.c index 20b21f115..7b6f09a1c 100644 --- a/file.c +++ b/file.c @@ -499,7 +499,7 @@ char *parse_mkvi_value(const char *haystack, const char *needle) terminator = '\r'; } *endptr = 0; - ret = strdup(valueptr); + ret = copy_string(valueptr); *endptr = terminator; } @@ -513,12 +513,11 @@ char *next_mkvi_key(const char *haystack) if ((valueptr = strstr(haystack, "\n")) != NULL) { valueptr += 1; - } - if ((endptr = strstr(valueptr, ": ")) != NULL) { - *endptr = 0; - ret = strdup(valueptr); - *endptr = ':'; - + if ((endptr = strstr(valueptr, ": ")) != NULL) { + *endptr = 0; + ret = strdup(valueptr); + *endptr = ':'; + } } return ret; } diff --git a/parse-xml.c b/parse-xml.c index 9b5f97e21..45ac984df 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -1762,7 +1762,7 @@ static const char *nodename(xmlNode *node, char *buf, int len) int levels = 2; char *p = buf; - if (node->type != XML_CDATA_SECTION_NODE && (!node || !node->name)) { + if (!node || (node->type != XML_CDATA_SECTION_NODE && !node->name)) { return "root"; }