Skip to contentSkip to conversation

s390x/s390-virtio-ccw: fix loadparm property getter

PATCH In review Halil Pasic 3 participants 4 messages Jul 23, 2020 – Jul 27, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/s390-virtio-ccw: fix loadparm property getter

The function machine_get_loadparm() is supposed to produce as C-string, that is a null-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 null-terminated one.

Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")
---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +5 -1
index 8cc2f25d8a..e0e4a69ac8 100644
@@ -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 null-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)

base-commit: 53ce7b47b5bf47db067b81c18c786ed7b792d031

Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Halil Pasic

The function machine_get_loadparm() is supposed to produce as C-string,

sed "s/ as / a /"

Quoted 1 line

that is a null-terminated one, but it does not. ElectricFence can detect

maybe: sed "s/null/NUL/"

Quoted 3 lines

this problem if the loadparm machine property is used.

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

dito

Quoted 11 lines
Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")
---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index 8cc2f25d8a..e0e4a69ac8 100644

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 706

Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +2 -1
@@ -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 null-terminated string */

maybe: sed "s/null/NUL/"

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 707

Quoted 1 line
hw/s390x/s390-virtio-ccw.c +1 -0
+     loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);

Wrong indentation.

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 710

Quoted 3 lines
hw/s390x/s390-virtio-ccw.c +2 -0
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;
 }

With the cosmetics fixed:

#2 lore raw
Quoted 8 lines · On Thu, 23 Jul 2020 18:37:50 +0200 Thomas Huth <[email protected]> wrote:
Quoted 1 line · Halil Pasic

The function machine_get_loadparm() is supposed to produce as C-string,

sed "s/ as / a /"

Quoted 1 line

that is a null-terminated one, but it does not. ElectricFence can detect

maybe: sed "s/null/NUL/"

"NUL" seems to be the more commonly used form in QEMU, so I went ahead and changed it.

Quoted 32 lines
Quoted 4 lines

this problem if the loadparm machine property is used.

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

dito

Quoted 11 lines
Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")
---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +0 -0
index 8cc2f25d8a..e0e4a69ac8 100644

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 706

Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +2 -1
@@ -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 null-terminated string */  

maybe: sed "s/null/NUL/"

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 707

Quoted 1 line
hw/s390x/s390-virtio-ccw.c +1 -0
+     loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);  

Wrong indentation.

Quoted 7 lines

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 710

Quoted 3 lines
hw/s390x/s390-virtio-ccw.c +2 -0
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;
 }  

With the cosmetics fixed:

Thanks, queued to s390-fixes (with the nits fixed.)

#3 lore raw
In reply to Thomas Huth
Quoted 5 lines · On Thu, 23 Jul 2020 18:37:50 +0200 Thomas Huth <[email protected]> wrote:
Quoted 1 line · Halil Pasic

The function machine_get_loadparm() is supposed to produce as C-string,

sed "s/ as / a /"

Nod.

Quoted 4 lines
Quoted 1 line

that is a null-terminated one, but it does not. ElectricFence can detect

maybe: sed "s/null/NUL/"

https://en.wikipedia.org/wiki/Null-terminated_string

but it does not matter to me all that much.

Quoted 22 lines
Quoted 3 lines

this problem if the loadparm machine property is used.

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

dito

Quoted 16 lines
Fixes 7104bae9de ("hw/s390x: provide loadparm property for the machine")
---
 hw/s390x/s390-virtio-ccw.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +1 -0
index 8cc2f25d8a..e0e4a69ac8 100644
@@ -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;
 
Quoted 8 lines

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 706

Quoted 2 lines
hw/s390x/s390-virtio-ccw.c +1 -1
-    return g_memdup(ms->loadparm, sizeof(ms->loadparm));
+    /* make a null-terminated string */

maybe: sed "s/null/NUL/"

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 707

Quoted 1 line
hw/s390x/s390-virtio-ccw.c +1 -0
+     loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);

Wrong indentation.

Nod.

Quoted 10 lines

hw/s390x/s390-virtio-ccw.c bool hpage_1m_allowed(void) · line 710

Quoted 4 lines
hw/s390x/s390-virtio-ccw.c +2 -0
+    loadparm_str[sizeof(ms->loadparm)] = 0;
+    return loadparm_str;
 }

With the cosmetics fixed:

Thanks!

Regards,
Halil