Diagnose EOF on memory BIOs (or you just get mysterious errors with no error
[openssl.git] / crypto / bio / bss_mem.c
index 41eab92415e2cbb38bf2db852490b162179cd2f7..c4e557822e561ade40d960232c0acc5c256521b1 100644 (file)
 #include "cryptlib.h"
 #include <openssl/bio.h>
 
-static int mem_write(BIO *h,char *buf,int num);
-static int mem_read(BIO *h,char *buf,int size);
-static int mem_puts(BIO *h,char *str);
-static int mem_gets(BIO *h,char *str,int size);
-static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
+static int mem_write(BIO *h, const char *buf, int num);
+static int mem_read(BIO *h, char *buf, int size);
+static int mem_puts(BIO *h, const char *str);
+static int mem_gets(BIO *h, char *str, int size);
+static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
 static int mem_new(BIO *h);
 static int mem_free(BIO *data);
 static BIO_METHOD mem_method=
@@ -166,11 +166,13 @@ static int mem_read(BIO *b, char *out, int outl)
                if (b->num != 0)
                        BIO_set_retry_read(b);
                ret= b->num;
+               if(ret < 0)
+                   BIOerr(BIO_F_MEM_READ,BIO_R_EOF_ON_MEMORY_BIO);
                }
        return(ret);
        }
 
-static int mem_write(BIO *b, char *in, int inl)
+static int mem_write(BIO *b, const char *in, int inl)
        {
        int ret= -1;
        int blen;
@@ -198,7 +200,7 @@ end:
        return(ret);
        }
 
-static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
+static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
        {
        long ret=1;
        char **pptr;
@@ -300,7 +302,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
        return(ret);
        }
 
-static int mem_puts(BIO *bp, char *str)
+static int mem_puts(BIO *bp, const char *str)
        {
        int n,ret;