s390x/s390-virtio-ccw: fix off-by-one in loadparm getter
As pointed out by Peter, g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1)
reads one past of the end of ms->loadparm, so g_memdup() can not be used
here.
Let's use g_strndup instead!
Fixes: d664548328
("s390x/s390-virtio-ccw: fix loadparm property getter")
Fixes: Coverity CID 1431058
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200730130156.35063-1-pasic@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
This commit is contained in:
parent
5772f2b1fc
commit
148d25e0f6
@ -701,12 +701,9 @@ bool hpage_1m_allowed(void)
|
||||
static char *machine_get_loadparm(Object *obj, Error **errp)
|
||||
{
|
||||
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
|
||||
char *loadparm_str;
|
||||
|
||||
/* make a NUL-terminated string */
|
||||
loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
|
||||
loadparm_str[sizeof(ms->loadparm)] = 0;
|
||||
return loadparm_str;
|
||||
return g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
|
||||
}
|
||||
|
||||
static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
|
||||
|
Loading…
Reference in New Issue
Block a user