提交 fdee9d94 authored 作者: Travis Cross's avatar Travis Cross

Deal with read errors in switch_xml.c

Unlike fread(3), read(3) will return -1 on error.  We were assigning
the result of read to a potentially unsigned variable, and passing the
result down to switch_xml_parse_str() where it would end up
determining how many bytes to malloc(3).
上级 a1b536be
......@@ -1198,7 +1198,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
{
switch_xml_root_t root;
struct stat st;
switch_size_t l;
switch_ssize_t l;
void *m;
if (fd < 0)
......@@ -1212,8 +1212,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_fd(int fd)
m = malloc(st.st_size);
if (!m)
return NULL;
l = read(fd, m, st.st_size);
if (!l || !(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) {
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;
}
......@@ -1583,7 +1583,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
{
int fd = -1;
struct stat st;
switch_size_t l;
switch_ssize_t l;
void *m;
switch_xml_root_t root;
......@@ -1592,7 +1592,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file_simple(const char *file)
if (!st.st_size) goto error;
m = malloc(st.st_size);
switch_assert(m);
if (!(l = read(fd, m, st.st_size))) goto error;
if (!(0<(l = read(fd, m, st.st_size)))) goto error;
if (!(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) goto error;
root->dynamic = 1;
close(fd);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论