From: Dr. Stephen Henson Date: Thu, 4 Mar 1999 23:29:51 +0000 (+0000) Subject: Deleted my str_dup() function from X509V3: the same functionality is provided X-Git-Tag: OpenSSL_0_9_2b~89 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9985bed331b388e871a89cf043ae21c1177eaa24;p=oweals%2Fopenssl.git Deleted my str_dup() function from X509V3: the same functionality is provided by BUF_MEM_strdup(). Added text documentation to the BUF_MEM stuff. --- diff --git a/CHANGES b/CHANGES index 87069aa257..f6800dcf1d 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,9 @@ 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 diff --git a/crypto/x509v3/v3_enum.c b/crypto/x509v3/v3_enum.c index 3ce97cd560..835bde919f 100644 --- a/crypto/x509v3/v3_enum.c +++ b/crypto/x509v3/v3_enum.c @@ -97,7 +97,7 @@ ASN1_ENUMERATED *e; 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); } diff --git a/crypto/x509v3/v3_lib.c b/crypto/x509v3/v3_lib.c index 0500ef5a35..268617303f 100644 --- a/crypto/x509v3/v3_lib.c +++ b/crypto/x509v3/v3_lib.c @@ -64,7 +64,7 @@ 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) diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 0d2ae9dac3..40b7810d0d 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -66,15 +66,6 @@ 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) @@ -84,8 +75,8 @@ STACK **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; @@ -237,7 +228,7 @@ char *line; 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 */ diff --git a/crypto/x509v3/x509v3.h b/crypto/x509v3/x509v3.h index f40bb027f3..1f25fc8f86 100644 --- a/crypto/x509v3/x509v3.h +++ b/crypto/x509v3/x509v3.h @@ -237,7 +237,6 @@ int i2d_ext_ku(STACK *a, unsigned char **pp); 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); @@ -308,8 +307,6 @@ STACK *d2i_ext_ku(); 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(); diff --git a/doc/buffer.txt b/doc/buffer.txt new file mode 100644 index 0000000000..06d821cba0 --- /dev/null +++ b/doc/buffer.txt @@ -0,0 +1,49 @@ +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.