Coverage Report

Created: 2017-10-25 09:10

/root/src/xen/xen/common/guestcopy.c
Line
Count
Source (jump to first uncovered line)
1
#include <xen/lib.h>
2
#include <xen/guest_access.h>
3
#include <xen/err.h>
4
5
/*
6
 * The function copies a string from the guest and adds a NUL to
7
 * make sure the string is correctly terminated.
8
 */
9
char *safe_copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf,
10
                                  size_t size, size_t max_size)
11
0
{
12
0
    char *tmp;
13
0
14
0
    if ( size > max_size )
15
0
        return ERR_PTR(-ENOBUFS);
16
0
17
0
    /* Add an extra +1 to append \0 */
18
0
    tmp = xmalloc_array(char, size + 1);
19
0
    if ( !tmp )
20
0
        return ERR_PTR(-ENOMEM);
21
0
22
0
    if ( copy_from_guest(tmp, u_buf, size) )
23
0
    {
24
0
        xfree(tmp);
25
0
        return ERR_PTR(-EFAULT);
26
0
    }
27
0
    tmp[size] = '\0';
28
0
29
0
    return tmp;
30
0
}