Skip to content

Commit d664548

Browse files
halil-pasiccohuck
authored andcommitted
s390x/s390-virtio-ccw: fix loadparm property getter
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 <[email protected]> Reviewed-by: Thomas Huth <[email protected]> Message-Id: <[email protected]> Signed-off-by: Cornelia Huck <[email protected]>
1 parent d1bb69d commit d664548

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hw/s390x/s390-virtio-ccw.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
701701
static char *machine_get_loadparm(Object *obj, Error **errp)
702702
{
703703
S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
704+
char *loadparm_str;
704705

705-
return g_memdup(ms->loadparm, sizeof(ms->loadparm));
706+
/* make a NUL-terminated string */
707+
loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
708+
loadparm_str[sizeof(ms->loadparm)] = 0;
709+
return loadparm_str;
706710
}
707711

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

0 commit comments

Comments
 (0)