Fix typo in OBJ_txt2obj which incorrectly passed the content
[openssl.git] / crypto / objects / obj_dat.c
index fbbc03858aca3c719598ca950968b7fb770f4d82..ce779dc1b5beb143bf300e552ed0767078060bf3 100644 (file)
@@ -176,7 +176,6 @@ static int add_cmp(const void *ca_void, const void *cb_void)
                /* abort(); */
                return 0;
                }
-       return(1); /* should not get here */
        }
 
 static int init_added(void)
@@ -237,7 +236,7 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
        if (added == NULL)
                if (!init_added()) return(0);
        if ((o=OBJ_dup(obj)) == NULL) goto err;
-       ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ));
+       if (!(ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err;
        if ((o->length != 0) && (obj->data != NULL))
                ao[ADDED_DATA]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ));
        if (o->sn != NULL)
@@ -426,7 +425,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
        a2d_ASN1_OBJECT(p,i,s,-1);
        
        p=buf;
-       op=d2i_ASN1_OBJECT(NULL,&p,i);
+       op=d2i_ASN1_OBJECT(NULL,&p,j);
        OPENSSL_free(buf);
        return op;
        }
@@ -437,7 +436,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
        unsigned long l;
        unsigned char *p;
        const char *s;
-       char tbuf[32];
+       char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
 
        if (buf_len <= 0) return(0);
 
@@ -446,8 +445,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
                return(0);
        }
 
-       nid=OBJ_obj2nid(a);
-       if ((nid == NID_undef) || no_name) {
+       if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
                len=a->length;
                p=a->data;
 
@@ -655,6 +653,8 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
                return(0);
                }
        i=a2d_ASN1_OBJECT(buf,i,oid,-1);
+       if (i == 0)
+               goto err;
        op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
        if (op == NULL) 
                goto err;