Ugh, BIO_find_type() cannot be passed a NULL.
[openssl.git] / crypto / bio / bio_lib.c
index d8cb83aaabaf8c592588cfefeba7d48a7dacda8b..381afc9b8e03a05d5e8b3459e5a3d9facc4b5055 100644 (file)
@@ -201,13 +201,7 @@ int BIO_write(BIO *b, const void *in, int inl)
 
        if (i > 0) b->num_write+=(unsigned long)i;
 
-       /* This is evil and not thread safe.  If the BIO has been freed,
-        * we must not call the callback.  The only way to be able to
-        * determine this is the reference count which is now invalid since
-        * the memory has been free()ed.
-        */
-       if (b->references <= 0) abort();
-       if (cb != NULL) /* && (b->references >= 1)) */
+       if (cb != NULL)
                i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
                        0L,(long)i);
        return(i);
@@ -238,6 +232,8 @@ int BIO_puts(BIO *b, const char *in)
 
        i=b->method->bputs(b,in);
 
+       if (i > 0) b->num_write+=(unsigned long)i;
+
        if (cb != NULL)
                i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
                        0L,(long)i);
@@ -422,6 +418,7 @@ BIO *BIO_find_type(BIO *bio, int type)
        {
        int mt,mask;
 
+       if(!bio) return NULL;
        mask=type&0xff;
        do      {
                if (bio->method != NULL)
@@ -440,6 +437,12 @@ BIO *BIO_find_type(BIO *bio, int type)
        return(NULL);
        }
 
+BIO *BIO_next(BIO *b)
+       {
+       if(!b) return NULL;
+       return b->next_bio;
+       }
+
 void BIO_free_all(BIO *bio)
        {
        BIO *b;