[gnome-keyring] [gp11] gp11_object_get_data null terminates.



commit cdb17597cee9936f0d91ac5238ef343a5a2a2c7c
Author: Stef Walter <stef memberwebs com>
Date:   Wed Dec 16 03:59:01 2009 +0000

    [gp11] gp11_object_get_data null terminates.
    
    Make gp11_object_get_data null terminate the data it returns
    for convenience and efficiency. This is especially nice when
    using a custom allocator such as secure memory.

 gp11/gp11-object.c |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/gp11/gp11-object.c b/gp11/gp11-object.c
index 6f109bf..3bcfe75 100644
--- a/gp11/gp11-object.c
+++ b/gp11/gp11-object.c
@@ -1077,17 +1077,19 @@ perform_get_attribute_data (GetAttributeData *args)
 		return rv;
 	
 	/* Allocate memory for the value */
-	args->result = (args->allocator) (NULL, attr.ulValueLen ? attr.ulValueLen : 1);
+	args->result = (args->allocator) (NULL, attr.ulValueLen + 1);
 	g_assert (args->result);
 	attr.pValue = args->result;
-	
+
 	/* Now get the actual value */
 	rv = (args->base.pkcs11->C_GetAttributeValue) (args->base.handle, args->object,
 	                                               &attr, 1);
 
-	if (rv == CKR_OK)
+	if (rv == CKR_OK) {
 		args->n_result = attr.ulValueLen;
-	
+		args->result[args->n_result] = 0;
+	}
+
 	return rv;
 }
 
@@ -1106,8 +1108,10 @@ free_get_attribute_data (GetAttributeData *args)
  * @n_data: The length of the resulting data.
  * @err: A location to store an error.
  * 
- * Get the data for the specified attribute from the object. This call 
- * may block for an indefinite period.
+ * Get the data for the specified attribute from the object. For convenience
+ * the returned data has a null terminator.
+ *
+ * This call may block for an indefinite period.
  * 
  * Return value: The resulting PKCS#11 attribute data, or NULL if an error occurred. 
  **/
@@ -1130,8 +1134,10 @@ gp11_object_get_data (GP11Object *self, gulong attr_type, gsize *n_data, GError
  * @n_data: The length of the resulting data.
  * @err: A location to store an error.
  * 
- * Get the data for the specified attribute from the object. This call 
- * may block for an indefinite period.
+ * Get the data for the specified attribute from the object. For convenience
+ * the returned data has an extra null terminator, not included in the returned length.
+ *
+ * This call may block for an indefinite period.
  * 
  * Return value: The resulting PKCS#11 attribute data, or NULL if an error occurred. 
  **/
@@ -1183,8 +1189,9 @@ gp11_object_get_data_full (GP11Object *self, gulong attr_type, GP11Allocator all
  * @callback: Called when the operation completes.
  * @user_data: Data to be passed to the callback.
  * 
- * Get the data for the specified attribute from the object. This call will
- * return immediately and complete asynchronously.
+ * Get the data for the specified attribute from the object.
+ *
+ * This call will return immediately and complete asynchronously.
  **/
 void
 gp11_object_get_data_async (GP11Object *self, gulong attr_type, GP11Allocator allocator, 
@@ -1218,8 +1225,10 @@ gp11_object_get_data_async (GP11Object *self, gulong attr_type, GP11Allocator al
  * @n_data: The length of the resulting data.
  * @err: A location to store an error.
  *
- * Get the result of an operation to get attribute data from 
- * an object. 
+ * Get the result of an operation to get attribute data from
+ * an object. For convenience the returned data has an extra null terminator,
+ * not included in the returned length.
+ *
  * 
  * Return value: The PKCS#11 attribute data or NULL if an error occurred.
  **/



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