List Info

Thread: OpenSSL: openssl/crypto/asn1/ a_object.c asn1.h tasn_enc.c opens...




OpenSSL: openssl/crypto/asn1/ a_object.c asn1.h tasn_enc.c opens...
country flaguser name
Germany
2007-09-18 17:15:44
  OpenSSL CVS Repository
  http://cvs.openssl.org/
 
____________________________________________________________
________________

  Server: cvs.openssl.org                  Name:   Andy
Polyakov
  Root:   /v/openssl/cvs                   Email:  approopenssl.org
  Module: openssl                          Date:  
19-Sep-2007 00:15:36
  Branch: HEAD                             Handle:
2007091823152209

  Modified files:
    openssl/crypto/asn1     a_object.c asn1.h tasn_enc.c
    openssl/crypto/objects  obj_lib.c

  Log:
    Addenum to "Constify obj_dat.[ch]."

  Summary:
    Revision    Changes     Path
    1.24        +15 -7      openssl/crypto/asn1/a_object.c
    1.152       +1  -1      openssl/crypto/asn1/asn1.h
    1.18        +2  -1      openssl/crypto/asn1/tasn_enc.c
    1.8         +18 -17    
openssl/crypto/objects/obj_lib.c
 
____________________________________________________________
________________

  patch -p0 <<' .'
  Index: openssl/crypto/asn1/a_object.c
 
============================================================
================
  $ cvs diff -u -r1.23 -r1.24 a_object.c
  --- openssl/crypto/asn1/a_object.c	15 Mar 2006 17:45:41
-0000	1.23
  +++ openssl/crypto/asn1/a_object.c	18 Sep 2007 22:15:22
-0000	1.24
   -287,6 +287,7 
   	{
   	ASN1_OBJECT *ret=NULL;
   	const unsigned char *p;
  +	unsigned char *data;
   	int i;
   
   	/* only the ASN1_OBJECTs from the 'table' will have
values
   -299,15 +300,22 
   	else	ret=(*a);
   
   	p= *pp;
  -	if ((ret->data == NULL) || (ret->length <
len))
  +	/* detach data from object */
  +	data = (unsigned char *)ret->data;
  +	ret->data = NULL;
  +	/* once detached we can change it */
  +	if ((data == NULL) || (ret->length < len))
   		{
  -		if (ret->data != NULL) OPENSSL_free(ret->data);
  -		ret->data=(unsigned char *)OPENSSL_malloc(len ?
(int)len : 1);
  -		ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
  -		if (ret->data == NULL)
  +		ret->length=0;
  +		if (data != NULL) OPENSSL_free(data);
  +		data=(unsigned char *)OPENSSL_malloc(len ? (int)len :
1);
  +		if (data == NULL)
   			{ i=ERR_R_MALLOC_FAILURE; goto err; }
  +		ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
   		}
  -	memcpy(ret->data,p,(int)len);
  +	memcpy(data,p,(int)len);
  +	/* reattach data to object, after which it remains const
*/
  +	ret->data  =data;
   	ret->length=(int)len;
   	ret->sn=NULL;
   	ret->ln=NULL;
   -356,7 +364,7 
   		}
   	if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
   		{
  -		if (a->data != NULL) OPENSSL_free(a->data);
  +		if (a->data != NULL) OPENSSL_free((void
*)a->data);
   		a->data=NULL;
   		a->length=0;
   		}
   .
  patch -p0 <<' .'
  Index: openssl/crypto/asn1/asn1.h
 
============================================================
================
  $ cvs diff -u -r1.151 -r1.152 asn1.h
  --- openssl/crypto/asn1/asn1.h	7 Jun 2007 13:14:35
-0000	1.151
  +++ openssl/crypto/asn1/asn1.h	18 Sep 2007 22:15:24
-0000	1.152
   -208,7 +208,7 
   	const char *sn,*ln;
   	int nid;
   	int length;
  -	unsigned char *data;
  +	const unsigned char *data;	/* data remains const after
init */
   	int flags;	/* Should we free this one */
   	} ASN1_OBJECT;
   
   .
  patch -p0 <<' .'
  Index: openssl/crypto/asn1/tasn_enc.c
 
============================================================
================
  $ cvs diff -u -r1.17 -r1.18 tasn_enc.c
  --- openssl/crypto/asn1/tasn_enc.c	16 Nov 2006 00:19:35
-0000	1.17
  +++ openssl/crypto/asn1/tasn_enc.c	18 Sep 2007 22:15:25
-0000	1.18
   -569,7 +569,8 
   	ASN1_STRING *strtmp;
   	ASN1_OBJECT *otmp;
   	int utype;
  -	unsigned char *cont, c;
  +	const unsigned char *cont;
  +	unsigned char c;
   	int len;
   	const ASN1_PRIMITIVE_FUNCS *pf;
   	pf = it->funcs;
   .
  patch -p0 <<' .'
  Index: openssl/crypto/objects/obj_lib.c
 
============================================================
================
  $ cvs diff -u -r1.7 -r1.8 obj_lib.c
  --- openssl/crypto/objects/obj_lib.c	29 Jan 2006 23:12:15
-0000	1.7
  +++ openssl/crypto/objects/obj_lib.c	18 Sep 2007 22:15:31
-0000	1.8
   -66,7 +66,8 
   	{
   	ASN1_OBJECT *r;
   	int i;
  -	char *ln=NULL;
  +	char *ln=NULL,*sn=NULL;
  +	unsigned char *data=NULL;
   
   	if (o == NULL) return(NULL);
   	if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
   -79,42 +80,42 
   		OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
   		return(NULL);
   		}
  -	r->data=OPENSSL_malloc(o->length);
  -	if (r->data == NULL)
  +	data=OPENSSL_malloc(o->length);
  +	if (data == NULL)
   		goto err;
   	if (o->data != NULL)
  -		memcpy(r->data,o->data,o->length);
  +		memcpy(data,o->data,o->length);
  +	/* once data attached to object it remains const */
  +	r->data = data;
   	r->length=o->length;
   	r->nid=o->nid;
   	r->ln=r->sn=NULL;
   	if (o->ln != NULL)
   		{
   		i=strlen(o->ln)+1;
  -		r->ln=ln=OPENSSL_malloc(i);
  -		if (r->ln == NULL) goto err;
  +		ln=OPENSSL_malloc(i);
  +		if (ln == NULL) goto err;
   		memcpy(ln,o->ln,i);
  +		r->ln=ln;
   		}
   
   	if (o->sn != NULL)
   		{
  -		char *s;
  -
   		i=strlen(o->sn)+1;
  -		r->sn=s=OPENSSL_malloc(i);
  -		if (r->sn == NULL) goto err;
  -		memcpy(s,o->sn,i);
  +		sn=OPENSSL_malloc(i);
  +		if (sn == NULL) goto err;
  +		memcpy(sn,o->sn,i);
  +		r->sn=sn;
   		}
   	r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
  
		ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_
DATA);
   	return(r);
   err:
   	OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
  -	if (r != NULL)
  -		{
  -		if (ln != NULL) OPENSSL_free(ln);
  -		if (r->data != NULL) OPENSSL_free(r->data);
  -		OPENSSL_free(r);
  -		}
  +	if (ln != NULL)		OPENSSL_free(ln);
  +	if (sn != NULL)		OPENSSL_free(sn);
  +	if (data != NULL)	OPENSSL_free(data);
  +	if (r != NULL)		OPENSSL_free(r);
   	return(NULL);
   	}
   
   .
____________________________________________________________
__________
OpenSSL Project                                 http://www.openssl.org
CVS Repository Commit List                    
openssl-cvsopenssl.org
Automated List Manager                          
majordomoopenssl.org

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )