Skip to content

Commit

Permalink
s390x/s390-virtio-ccw: fix loadparm property getter
Browse files Browse the repository at this point in the history
The function machine_get_loadparm() is supposed to produce a C-string,
that is a NUL-terminated one, but it does not. ElectricFence can detect
this problem if the loadparm machine property is used.

Let us make the returned string a NUL-terminated one.

Fixes: 7104bae ("hw/s390x: provide loadparm property for the machine")
Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200723162717.88485-1-pasic@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
  • Loading branch information
halil-pasic authored and cohuck committed Jul 24, 2020
1 parent d1bb69d commit d664548
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hw/s390x/s390-virtio-ccw.c
Expand Up @@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
static char *machine_get_loadparm(Object *obj, Error **errp)
{
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
char *loadparm_str;

return g_memdup(ms->loadparm, sizeof(ms->loadparm));
/* make a NUL-terminated string */
loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
loadparm_str[sizeof(ms->loadparm)] = 0;
return loadparm_str;
}

static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
Expand Down

0 comments on commit d664548

Please sign in to comment.