mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
[core] Coverity fixes
* [core] Coverity CID 1024233 (Dereference before null check) * [core] Coverity CID 1024239 (Dereference before null check) * [core] Coverity CID 1024242 (Dereference before null check) * [core] Coverity CID 1024243 (Dereference before null check) * [core] Coverity CID 1024453 (Dereference before null check) * [core] Coverity CID 1024554 (Logically dead code) * [core] Coverity CID 1024868 (unchecked return value from library) * [core] Coverity CID 1024869 (unchecked return value from library) * [core] Coverity CID 1468281 (Dereference before null check) * [core] Coverity CID 1024238 (Dereference before null check) * [core] Coverity CID 1468621 (Copy into fixed size buffer) * [core] Coverity CID 1024871 (Unchecked return value)
This commit is contained in:
+26
-10
@@ -550,15 +550,22 @@ SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target
|
||||
switch_xml_root_t root = (switch_xml_root_t) xml;
|
||||
int i = 0;
|
||||
|
||||
if (!root)
|
||||
if (!root) {
|
||||
return (const char **) SWITCH_XML_NIL;
|
||||
while (root->xml.parent)
|
||||
}
|
||||
|
||||
while (root && root->xml.parent) {
|
||||
root = (switch_xml_root_t) root->xml.parent; /* root tag */
|
||||
}
|
||||
|
||||
if (!root || !root->pi) {
|
||||
return (const char **) SWITCH_XML_NIL;
|
||||
}
|
||||
while (root->pi[i] && strcmp(target, root->pi[i][0]))
|
||||
|
||||
while (root->pi[i] && strcmp(target, root->pi[i][0])) {
|
||||
i++; /* find target */
|
||||
}
|
||||
|
||||
return (const char **) ((root->pi[i]) ? root->pi[i] + 1 : SWITCH_XML_NIL);
|
||||
}
|
||||
|
||||
@@ -1146,7 +1153,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
|
||||
return switch_xml_err(root, d, "unclosed <!--");
|
||||
} else if (!strncmp(s, "![CDATA[", 8)) { /* cdata */
|
||||
if ((s = strstr(s, "]]>"))) {
|
||||
if (root && root->cur) {
|
||||
if (root->cur) {
|
||||
root->cur->flags |= SWITCH_XML_CDATA;
|
||||
}
|
||||
switch_xml_char_content(root, d + 8, (s += 2) - d - 10, 'c');
|
||||
@@ -1213,10 +1220,18 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fp(FILE * fp)
|
||||
}
|
||||
} while (s && l == SWITCH_XML_BUFSIZE);
|
||||
|
||||
if (!s)
|
||||
if (!s) {
|
||||
return NULL;
|
||||
root = (switch_xml_root_t) switch_xml_parse_str(s, len);
|
||||
}
|
||||
|
||||
if (!(root = (switch_xml_root_t) switch_xml_parse_str(s, len))) {
|
||||
free(s);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root->dynamic = 1; /* so we know to free s in switch_xml_free() */
|
||||
|
||||
return &root->xml;
|
||||
}
|
||||
|
||||
@@ -1232,9 +1247,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
|
||||
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
fstat(fd, &st);
|
||||
|
||||
if (!st.st_size) {
|
||||
if (fstat(fd, &st) == -1 || !st.st_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1243,8 +1257,10 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
|
||||
if (!(0<(l = read(fd, m, st.st_size)))
|
||||
|| !(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) {
|
||||
free(m);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root->dynamic = 1; /* so we know to free s in switch_xml_free() */
|
||||
|
||||
return &root->xml;
|
||||
@@ -1637,8 +1653,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
|
||||
switch_xml_root_t root;
|
||||
|
||||
if ((fd = open(file, O_RDONLY, 0)) > -1) {
|
||||
fstat(fd, &st);
|
||||
if (!st.st_size) {
|
||||
if (fstat(fd, &st) == -1 || !st.st_size) {
|
||||
close(fd);
|
||||
goto error;
|
||||
}
|
||||
@@ -1659,6 +1674,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
|
||||
|
||||
root->dynamic = 1;
|
||||
close(fd);
|
||||
|
||||
return &root->xml;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user