[PATCH 23/47] libsemanage: simplify malloc plus strcpy via strndup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>

Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx>
---
 libsemanage/src/parse_utils.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libsemanage/src/parse_utils.c b/libsemanage/src/parse_utils.c
index d9b12763..d3bc148b 100644
--- a/libsemanage/src/parse_utils.c
+++ b/libsemanage/src/parse_utils.c
@@ -290,14 +290,12 @@ int parse_fetch_string(semanage_handle_t * handle,
 		goto err;
 	}
 
-	tmp_str = (char *)malloc(len + 1);
+	tmp_str = strndup(start, len);
 	if (!tmp_str) {
 		ERR(handle, "out of memory");
 		goto err;
 	}
 
-	strncpy(tmp_str, start, len);
-	*(tmp_str + len) = '\0';
 	*str = tmp_str;
 	return STATUS_SUCCESS;
 
-- 
2.45.2





[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux