Skip to contentSkip to conversation

tests/qtest/migration: Ignore if socket-address is missing to avoid crash below

PATCH Applied Het Gala 3 participants 9 messages Mar 19, 2024 – Mar 20, 2024

lore
Share & tools
lore

Het Gala

author
#0 lore raw

PATCH 1/2 tests/qtest/migration: Ignore if socket-address is missing to avoid crash below

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

---
 tests/qtest/migration-helpers.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-helpers.c +4 -0
index b2a90469fb..fb7156f09a 100644
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
     QObject *object;
 
     rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
     object = qdict_get(rsp, "socket-address");
 
     iv = qobject_input_visitor_new(object);
Signature · 1 line
2.22.3
author
#1 lore raw

PATCH 2/2 tests/qtest/migration: Fix typo for vsock in SocketAddress_to_str

---
 tests/qtest/migration-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/migration-helpers.c +1 -1
index fb7156f09a..651c6c555a 100644
@@ -42,7 +42,7 @@ static char *SocketAddress_to_str(SocketAddress *addr)
     case SOCKET_ADDRESS_TYPE_FD:
         return g_strdup_printf("fd:%s", addr->u.fd.str);
     case SOCKET_ADDRESS_TYPE_VSOCK:
-        return g_strdup_printf("tcp:%s:%s",
+        return g_strdup_printf("vsock:%s:%s",
                                addr->u.vsock.cid,
                                addr->u.vsock.port);
     default:
Signature · 1 line
2.22.3
Applied
#2 lore raw

Re: [PATCH 2/2] tests/qtest/migration: Fix typo for vsock in SocketAddress_to_str

Quoted 10 lines · Het Gala
---
 tests/qtest/migration-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/migration-helpers.c +0 -0
index fb7156f09a..651c6c555a 100644

tests/qtest/migration-helpers.c static char *SocketAddress_to_str(SocketAddress *addr) · line 48

Quoted 8 lines
tests/qtest/migration-helpers.c +1 -1
@@ -42,7 +42,7 @@ static char *SocketAddress_to_str(SocketAddress *addr)
     case SOCKET_ADDRESS_TYPE_FD:
         return g_strdup_printf("fd:%s", addr->u.fd.str);
     case SOCKET_ADDRESS_TYPE_VSOCK:
-        return g_strdup_printf("tcp:%s:%s",
+        return g_strdup_printf("vsock:%s:%s",
                                addr->u.vsock.cid,
                                addr->u.vsock.port);
     default:

Queued for 9.1, thanks.

Signature · 1 line
Peter Xu
author
#3 lore raw
In reply to Het Gala

FYI: This 2 patches are rebased on top of another (tests/qtest/migration: Add tests for introducing 'channels' argument in migrate QAPIs) series. Can find the build for both the patches here: https://gitlab.com/galahet/Qemu/-/pipelines/1219841944

Quoted 17 lines · Het Gala

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

---
  tests/qtest/migration-helpers.c | 4 ++++
  1 file changed, 4 insertions(+)
tests/qtest/migration-helpers.c +0 -0
index b2a90469fb..fb7156f09a 100644

tests/qtest/migration-helpers.c static SocketAddress *migrate_get_socket_address(QTestState *who) · line 99

Quoted 10 lines
tests/qtest/migration-helpers.c +4 -0
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
      QObject *object;
 
      rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
      object = qdict_get(rsp, "socket-address");
 
      iv = qobject_input_visitor_new(object);

Regards,
Het Gala

#4 lore raw
In reply to Het Gala
Quoted 5 lines · Het Gala

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

Hmm, this patch isn't as clear to me. Even if this can return NULL now, it'll soon crash at some later point, no?

IMHO such patch is more suitable to be included in the same patch where such new tests will be introduced, then we're addressing some real test code changes that will work, rather than worrying on what will happen in the future (and as I mentioned, i don't think it fully resolved that either..)

Thanks,

Quoted 25 lines
---
 tests/qtest/migration-helpers.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-helpers.c +4 -0
index b2a90469fb..fb7156f09a 100644
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
     QObject *object;
 
     rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
     object = qdict_get(rsp, "socket-address");
 
     iv = qobject_input_visitor_new(object);
Signature · 1 line
2.22.3
Signature · 1 line
Peter Xu
author
#5 lore raw
Quoted 8 lines · Peter Xu
Quoted 5 lines · Het Gala

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

Hmm, this patch isn't as clear to me. Even if this can return NULL now, it'll soon crash at some later point, no?

It won't crash IMO, the next function SocketAddress_to_str for a non-socket type would return an proper error ?

Quoted 6 lines

IMHO such patch is more suitable to be included in the same patch where such new tests will be introduced, then we're addressing some real test code changes that will work, rather than worrying on what will happen in the future (and as I mentioned, i don't think it fully resolved that either..)

Thanks,

Maybe, Fabiano can pick this patch, and add along file migration qtests patch ?

Quoted 20 lines
Quoted 20 lines
---
  tests/qtest/migration-helpers.c | 4 ++++
  1 file changed, 4 insertions(+)
tests/qtest/migration-helpers.c +4 -0
index b2a90469fb..fb7156f09a 100644
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
      QObject *object;
 
      rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
      object = qdict_get(rsp, "socket-address");
 
Quoted 4 lines
Quoted 4 lines
tests/qtest/migration-helpers.c +0 -0
      iv = qobject_input_visitor_new(object);
Signature · 1 line
2.22.3

Regards,
Het Gala

#6 lore raw
Quoted 2 lines · Het Gala

It won't crash IMO, the next function SocketAddress_to_str for a non-socket type would return an proper error ?

Both SocketAddress_to_str() and SocketAddress_to_qdict() will crash with a NULL pointer passed in right now.

Thanks,

Signature · 1 line
Peter Xu
#7 lore raw
In reply to Het Gala
Quoted 11 lines · Het Gala
Quoted 8 lines · Peter Xu
Quoted 5 lines · Het Gala

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

Hmm, this patch isn't as clear to me. Even if this can return NULL now, it'll soon crash at some later point, no?

It won't crash IMO, the next function SocketAddress_to_str for a non-socket type would return an proper error ?

Quoted 8 lines
Quoted 6 lines

IMHO such patch is more suitable to be included in the same patch where such new tests will be introduced, then we're addressing some real test code changes that will work, rather than worrying on what will happen in the future (and as I mentioned, i don't think it fully resolved that either..)

Thanks,

Maybe, Fabiano can pick this patch, and add along file migration qtests patch ?

Yep.

Quoted 26 lines
Quoted 20 lines
Quoted 20 lines
---
  tests/qtest/migration-helpers.c | 4 ++++
  1 file changed, 4 insertions(+)
tests/qtest/migration-helpers.c +4 -0
index b2a90469fb..fb7156f09a 100644
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
      QObject *object;
 
      rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
      object = qdict_get(rsp, "socket-address");
 
Quoted 4 lines
Quoted 4 lines
tests/qtest/migration-helpers.c +0 -0
      iv = qobject_input_visitor_new(object);
Signature · 1 line
2.22.3

Regards,
Het Gala

author
#8 lore raw
Quoted 18 lines · Fabiano Rosas
Quoted 16 lines · Het Gala
Quoted 8 lines · Peter Xu
Quoted 5 lines · Het Gala

'object' can return NULL if there is no socket-address, such as with a file migration. Then the visitor code below fails and the test crashes.

Ignore and return NULL when socket-address is missing in the reply so we don't break future tests that use a non-socket type.

Hmm, this patch isn't as clear to me. Even if this can return NULL now, it'll soon crash at some later point, no?

It won't crash IMO, the next function SocketAddress_to_str for a non-socket type would return an proper error ?

Quoted 5 lines

IMHO such patch is more suitable to be included in the same patch where such new tests will be introduced, then we're addressing some real test code changes that will work, rather than worrying on what will happen in the future (and as I mentioned, i don't think it fully resolved that either..)

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Thanks,

Maybe, Fabiano can pick this patch, and add along file migration qtests patch ?

Yep.

Thanks

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
tests/qtest/migration-helpers.c +4 -0
@@ -90,6 +90,10 @@ static SocketAddress *migrate_get_socket_address(QTestState *who)
       QObject *object;
 
       rsp = migrate_query(who);
+
+    if (!qdict_haskey(rsp, "socket-address")) {
+        return NULL;
+    }
       object = qdict_get(rsp, "socket-address");
 
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
tests/qtest/migration-helpers.c +0 -0
       iv = qobject_input_visitor_new(object);
Signature · 1 line
2.22.3

Regards,
Het Gala

Regards,
Het Gala