[PATCH 05/11] virStorageBackendISCSISetAuth: Use g_strndup to '\0' terminate data

Peter Krempa pkrempa at redhat.com
Fri Dec 9 16:28:57 UTC 2022


Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/storage/storage_backend_iscsi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 78c86e6359..9f9aa01f05 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -281,9 +281,8 @@ virStorageBackendISCSISetAuth(const char *portal,
                                  &secret_value, &secret_size) < 0)
         goto cleanup;

-    secret_str = g_new0(char, secret_size + 1);
-    memcpy(secret_str, secret_value, secret_size);
-    secret_str[secret_size] = '\0';
+    /* '\0' terminate the data into a string */
+    secret_str = g_strndup((char *) secret_value, secret_size);

     if (virISCSINodeUpdate(portal,
                            source->devices[0].path,
-- 
2.38.1



More information about the libvir-list mailing list