aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_private.c
diff options
context:
space:
mode:
authorIan Jackson <ian.jackson@eu.citrix.com>2013-06-14 16:45:41 +0100
committerIan Jackson <Ian.Jackson@eu.citrix.com>2013-06-14 16:45:41 +0100
commita2986a7959919bc748784bb75970bfbd42697d3b (patch)
treee27e2d46beeb2b9c4ab5aa9ba40a8e71421bf104 /tools/libxc/xc_private.c
parent117a538dbef62f8d39159dea652e633e01b50a9a (diff)
downloadxen-a2986a7959919bc748784bb75970bfbd42697d3b.tar.gz
xen-a2986a7959919bc748784bb75970bfbd42697d3b.tar.bz2
xen-a2986a7959919bc748784bb75970bfbd42697d3b.zip
libxc: check return values from malloc
A sufficiently malformed input to libxc (such as a malformed input ELF or other guest-controlled data) might cause one of libxc's malloc() to fail. In this case we need to make sure we don't dereference or do pointer arithmetic on the result. Search for all occurrences of \b(m|c|re)alloc in libxc, and all functions which call them, and add appropriate error checking where missing. This includes the functions xc_dom_malloc*, which now print a message when they fail so that callers don't have to do so. The function xc_cpuid_to_str wasn't provided with a sane return value and has a pretty strange API, which now becomes a little stranger. There are no in-tree callers. Changes in the Xen 4.2 version of this series: * No need to fix code relating to ARM. * No need to fix code relating to superpage support. * Additionally fix `dom->p2m_host = xc_dom_malloc...' in xc_dom_ia64.c. Changes in the Xen 4.1 version of this series: * An additional check is needed in xc_flask.c:xc_flask_access. This is part of the fix to a security issue, XSA-55. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxc/xc_private.c')
-rw-r--r--tools/libxc/xc_private.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 09c8f23ca5..1bf25d2a1e 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -742,6 +742,8 @@ const char *xc_strerror(xc_interface *xch, int errcode)
errbuf = pthread_getspecific(errbuf_pkey);
if (errbuf == NULL) {
errbuf = malloc(XS_BUFSIZE);
+ if ( errbuf == NULL )
+ return "(failed to allocate errbuf)";
pthread_setspecific(errbuf_pkey, errbuf);
}