give more meaningful error if presented with wrong certificate type by server
[openssl.git] / crypto / bio / bss_mem.c
index 5e89537557f914cd763880a5553b97ffa1b95eff..37d4194e4bba5232e054b6389e0ecf4a1a5d9870 100644 (file)
@@ -100,7 +100,7 @@ BIO *BIO_new_mem_buf(void *buf, int len)
                BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
                return NULL;
        }
-       sz = (len<0) ? strlen(buf) : len;
+       sz = (len<0) ? strlen(buf) : (size_t)len;
        if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
        b = (BUF_MEM *)ret->ptr;
        b->data = buf;
@@ -149,7 +149,7 @@ static int mem_read(BIO *b, char *out, int outl)
 
        bm=(BUF_MEM *)b->ptr;
        BIO_clear_retry_flags(b);
-       ret=(outl >=0 && (size_t)outl > bm->length)?bm->length:outl;
+       ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl;
        if ((out != NULL) && (ret > 0)) {
                memcpy(out,bm->data,ret);
                bm->length-=ret;
@@ -280,6 +280,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
 
        BIO_clear_retry_flags(bp);
        j=bm->length;
+       if ((size-1) < j) j=size-1;
        if (j <= 0)
                {
                *buf='\0';
@@ -288,17 +289,18 @@ static int mem_gets(BIO *bp, char *buf, int size)
        p=bm->data;
        for (i=0; i<j; i++)
                {
-               if (p[i] == '\n') break;
-               }
-       if (i == j)
-               {
-               BIO_set_retry_read(bp);
-               /* return(-1);  change the semantics 0.6.6a */ 
+               if (p[i] == '\n')
+                       {
+                       i++;
+                       break;
+                       }
                }
-       else
-               i++;
-       /* i is the max to copy */
-       if ((size-1) < i) i=size-1;
+
+       /*
+        * i is now the max num of bytes to copy, either j or up to
+        * and including the first newline
+        */ 
+
        i=mem_read(bp,buf,i);
        if (i > 0) buf[i]='\0';
        ret=i;