- Added an error check and comment complementary to thayes's previous change
authorrepka%netscape.com
Thu, 06 Apr 2000 00:38:12 +0000
changeset 229 fecb2bfafe3cbda21e1c93de1facb37102ee2f9b
parent 228 755e39411d951ca545e9b31a1809d6b880d50656
child 230 d3006d31dd911e77da468221c9771a41b161a4eb
push idunknown
push userunknown
push dateunknown
- Added an error check and comment complementary to thayes's previous change (same as I had already made in my version, but he beat me to checking it in). - Some miscellaneous clean-up (typos, really).
security/nss/lib/util/nssb64d.c
--- a/security/nss/lib/util/nssb64d.c
+++ b/security/nss/lib/util/nssb64d.c
@@ -565,17 +565,17 @@ PL_Base64DecodeBuffer (const char *src, 
 
     /*
      * How much space could we possibly need for decoding this input?
      */
     need_length = PL_Base64MaxDecodedLength (srclen);
 
     /*
      * Make sure we have at least that much, if output buffer provided.
-     * If not output buffer provided, then we allocate that much.
+     * If no output buffer provided, then we allocate that much.
      */
     if (dest != NULL) {
 	PR_ASSERT(maxdestlen >= need_length);
 	if (maxdestlen < need_length) {
 	    PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
 	    goto loser;
 	}
 	output_buffer = dest;
@@ -729,23 +729,23 @@ NSSBase64Decoder_Destroy (NSSBase64Decod
 
 /*
  * Perform base64 decoding from an ascii string "inStr" to an Item.
  * The length of the input must be provided as "inLen".  The Item
  * may be provided (as "outItemOpt"); you can also pass in a NULL
  * and the Item will be allocated for you.
  *
  * In any case, the data within the Item will be allocated for you.
- * All allocation will happen out the passed-in "arenaOpt", if non-NULL.
+ * All allocation will happen out of the passed-in "arenaOpt", if non-NULL.
  * If "arenaOpt" is NULL, standard allocation (heap) will be used and
  * you will want to free the result via SECITEM_FreeItem.
  *
  * Return value is NULL on error, the Item (allocated or provided) otherwise.
  */
-extern SECItem *
+SECItem *
 NSSBase64_DecodeBuffer (PRArenaPool *arenaOpt, SECItem *outItemOpt,
 			const char *inStr, unsigned int inLen)
 {
     SECItem *out_item = outItemOpt;
     PRUint32 max_out_len = PL_Base64MaxDecodedLength (inLen);
     PRUint32 out_len;
     void *mark = NULL;
     unsigned char *dummy;
@@ -804,17 +804,17 @@ NSSBase64_DecodeBuffer (PRArenaPool *are
  */
 
 #include "base64.h"
 
 /*
 ** Return an PORT_Alloc'd string which is the base64 decoded version
 ** of the input string; set *lenp to the length of the returned data.
 */
-extern unsigned char *
+unsigned char *
 ATOB_AsciiToData(const char *string, unsigned int *lenp)
 {
     SECItem binary_item, *dummy;
 
     binary_item.data = NULL;
     binary_item.len = 0;
 
     dummy = NSSBase64_DecodeBuffer (NULL, &binary_item, string,
@@ -826,21 +826,33 @@ ATOB_AsciiToData(const char *string, uns
 
     *lenp = dummy->len;
     return dummy->data;
 }
  
 /*
 ** Convert from ascii to binary encoding of an item.
 */
-extern SECStatus
+SECStatus
 ATOB_ConvertAsciiToItem(SECItem *binary_item, char *ascii)
 {
     SECItem *dummy;
 
+    if (binary_item == NULL) {
+	PORT_SetError (SEC_ERROR_INVALID_ARGS);
+	return SECFailure;
+    }
+
+    /*
+     * XXX Would prefer to assert here if data is non-null (actually,
+     * don't need to, just let NSSBase64_DecodeBuffer do it), so as to
+     * to catch unintended memory leaks, but callers are not clean in
+     * this respect so we need to explicitly clear here to avoid the
+     * assert in NSSBase64_DecodeBuffer.
+     */
     binary_item->data = NULL;
     binary_item->len = 0;
 
     dummy = NSSBase64_DecodeBuffer (NULL, binary_item, ascii,
 				    (PRUint32) PORT_Strlen(ascii));
 
     if (dummy == NULL)
 	return SECFailure;