by BUF_MEM_strdup(). Added text documentation to the BUF_MEM stuff.
Changes between 0.9.1c and 0.9.2
+ *) Add text documentation for the BUFFER functions.
+ [Steve Henson]
+
*) Added the new `Includes OpenSSL Cryptography Software' button as
doc/openssl_button.{gif,html} which is similar in style to the old SSLeay
button and can be used by applications based on OpenSSL to show the
long strval;
strval = ASN1_ENUMERATED_get(e);
for(enam =(ENUMERATED_NAMES *)method->usr_data; enam->lname; enam++) {
- if(strval == enam->bitnum) return str_dup(enam->lname);
+ if(strval == enam->bitnum) return BUF_strdup(enam->lname);
}
return i2s_ASN1_ENUMERATED(method, e);
}
static STACK *ext_list = NULL;
-static ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
+static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
static void ext_list_free(X509V3_EXT_METHOD *ext);
int X509V3_EXT_add(ext)
static char *strip_spaces(char *name);
-char *str_dup(str)
-char *str;
-{
- char *tmp;
- if(!(tmp = Malloc(strlen(str) + 1))) return NULL;
- strcpy(tmp, str);
- return tmp;
-}
-
/* Add a CONF_VALUE name value pair to stack */
int X509V3_add_value(name, value, extlist)
{
CONF_VALUE *vtmp = NULL;
char *tname = NULL, *tvalue = NULL;
- if(name && !(tname = str_dup(name))) goto err;
- if(value && !(tvalue = str_dup(value))) goto err;;
+ if(name && !(tname = BUF_strdup(name))) goto err;
+ if(value && !(tvalue = BUF_strdup(value))) goto err;;
if(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err;
if(!*extlist && !(*extlist = sk_new(NULL))) goto err;
vtmp->section = NULL;
char *linebuf;
int state;
/* We are going to modify the line so copy it first */
- linebuf = str_dup(line);
+ linebuf = BUF_strdup(line);
state = HDR_NAME;
ntmp = NULL;
/* Go through all characters */
STACK *d2i_ext_ku(STACK **a, unsigned char **pp, long length);
void ext_ku_free(STACK *a);
STACK *ext_ku_new(void);
-char *str_dup(char *val);
#ifdef HEADER_CONF_H
GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
void ext_ku_free();
STACK *ext_ku_new();
-char *str_dup();
-
#ifdef HEADER_CONF_H
void X509V3_conf_free();
X509_EXTENSION *X509V3_EXT_conf_nid();
--- /dev/null
+BUFFER Library.
+
+[Note: I wrote this when I saw a Malloc version of strdup() in there which
+ I'd written myself anyway. I was so annoyed at not noticing this I decided to
+ document it :-) Steve.]
+
+The buffer library handles simple character arrays. Buffers are used for various
+purposes in the library, most notably memory BIOs.
+
+The library uses the BUF_MEM structure defined in buffer.h:
+
+typedef struct buf_mem_st
+ {
+ int length; /* current number of bytes */
+ char *data;
+ int max; /* size of buffer */
+ } BUF_MEM;
+
+'length' is the current size of the buffer in bytes, 'max' is the amount of
+memory allocated to the buffer. There are three functions which handle these
+and one "miscelanous" function.
+
+BUF_MEM *BUF_MEM_new()
+
+This allocates a new buffer of zero size. Returns the buffer or NULL on error.
+
+void BUF_MEM_free(BUF_MEM *a)
+
+This frees up an already existing buffer. The data is zeroed before freeing
+up in case the buffer contains sensitive data.
+
+int BUF_MEM_grow(BUF_MEM *str, int len)
+
+This changes the size of an already existing buffer. It returns zero on error
+or the new size (i.e. 'len'). Any data already in the buffer is preserved if
+it increases in size.
+
+char * BUF_strdup(char *str)
+
+This is the previously mentioned strdup function: like the standard library
+strdup() it copies a null terminated string into a block of allocated memory
+and returns a pointer to the allocated block.
+
+Unlike the standard C library strdup() this function uses Malloc() and so
+should be used in preference to the standard library strdup() because it can
+be used for memory leak checking or replacing the malloc() function.
+
+The memory allocated from BUF_strdup() should be freed up using the Free()
+function.