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

Peter Krempa posted 11 patches 3 years, 2 months ago
[PATCH 05/11] virStorageBackendISCSISetAuth: Use g_strndup to '\0' terminate data
Posted by Peter Krempa 3 years, 2 months ago
Signed-off-by: Peter Krempa <pkrempa@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