Solar Designer wrote:
>
> On Wed, Apr 24, 2002 at 04:04:53PM +0100, Ben Laurie wrote:
> > Solar Designer wrote:
> > > Thank you for working on this!
> >
> > OK, try the attached patch...
>
> It's almost right, except:
>
> > - do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf, siglen);
> > + do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf, siglen,
> > + "");
>
> I'd use the return value in here as well, or we get:
>
> jill!solar:~/build/openssl-SNAP-20020416$ apps/openssl dgst -md5 < /dev/log
> Read Error
> jill!solar:~/build/openssl-SNAP-20020416$ echo $?
> 0
>
> It could also be nice to report the filename and strerror(errno), or
> it is sometimes not immediately clear what the error messages apply to:
>
> jill!solar:~/build/openssl-SNAP-20020416$ apps/openssl dgst -md5 /bin/ls /dev/log
>/bin /usr/bin/id
> MD5(/bin/ls)= d93498d9f52c3dc0330ab930fe3ffc50
> Read Error
> Read Error
> MD5(/usr/bin/id)= 4b37435d0793aba2b602fd2da0d7f8c5
> jill!solar:~/build/openssl-SNAP-20020416$ echo $?
> 0
>
> ...and the zero exit status in that case is even worse.
>
> I am thinking something like "fread: /bin: Is a directory" printed to
> stderr and a non-zero exit if at least one of the arguments resulted in
> an error.
Well, here's an even bigger and better patch. Thanks for the continued
feedback.
Cheers,
Ben.
--
http://www.apache-ssl.org/ben.html http://www.thebunker.net/
"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff
Index: apps/dgst.c
===================================================================
RCS file: /e/openssl/cvs/openssl/apps/dgst.c,v
retrieving revision 1.23.2.2
diff -u -r1.23.2.2 dgst.c
--- apps/dgst.c 2002/04/06 18:59:57 1.23.2.2
+++ apps/dgst.c 2002/04/29 14:44:57
@@ -73,8 +73,9 @@
#undef PROG
#define PROG dgst_main
-void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
- EVP_PKEY *key, unsigned char *sigin, int siglen);
+int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
+ EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
+ const char *file);
int MAIN(int, char **);
@@ -319,22 +320,36 @@
if (argc == 0)
{
BIO_set_fp(in,stdin,BIO_NOCLOSE);
- do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf, siglen);
+ err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
+ siglen,"","(stdin)");
}
else
{
name=OBJ_nid2sn(md->type);
for (i=0; i<argc; i++)
{
+ char *tmp,*tofree=NULL;
+ int r;
+
if (BIO_read_filename(in,argv[i]) <= 0)
{
perror(argv[i]);
err++;
continue;
+ }
+ if(!out_bin)
+ {
+
+tmp=tofree=OPENSSL_malloc(strlen(name)+strlen(argv[i])+5);
+ sprintf(tmp,"%s(%s)= ",name,argv[i]);
}
- if(!out_bin) BIO_printf(out, "%s(%s)= ",name,argv[i]);
- do_fp(out, buf,inp,separator, out_bin, sigkey,
- sigbuf, siglen);
+ else
+ tmp="";
+ r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
+ siglen,tmp,argv[i]);
+ if(r)
+ err=r;
+ if(tofree)
+ OPENSSL_free(tofree);
(void)BIO_reset(bmd);
}
}
@@ -353,8 +368,9 @@
EXIT(err);
}
-void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
- EVP_PKEY *key, unsigned char *sigin, int siglen)
+int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
+ EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
+ const char *file)
{
int len;
int i;
@@ -362,21 +378,33 @@
for (;;)
{
i=BIO_read(bp,(char *)buf,BUFSIZE);
- if (i <= 0) break;
+ if(i < 0)
+ {
+ BIO_printf(bio_err, "Read Error in %s\n",file);
+ ERR_print_errors(bio_err);
+ return 1;
+ }
+ if (i == 0) break;
}
if(sigin)
{
EVP_MD_CTX *ctx;
BIO_get_md_ctx(bp, &ctx);
i = EVP_VerifyFinal(ctx, sigin, (unsigned int)siglen, key);
- if(i > 0) BIO_printf(out, "Verified OK\n");
- else if(i == 0) BIO_printf(out, "Verification Failure\n");
+ if(i > 0)
+ BIO_printf(out, "Verified OK\n");
+ else if(i == 0)
+ {
+ BIO_printf(out, "Verification Failure\n");
+ return 1;
+ }
else
{
BIO_printf(bio_err, "Error Verifying Data\n");
ERR_print_errors(bio_err);
+ return 1;
}
- return;
+ return 0;
}
if(key)
{
@@ -386,7 +414,7 @@
{
BIO_printf(bio_err, "Error Signing Data\n");
ERR_print_errors(bio_err);
- return;
+ return 1;
}
}
else
@@ -395,6 +423,7 @@
if(binout) BIO_write(out, buf, len);
else
{
+ BIO_write(out,title,strlen(title));
for (i=0; i<len; i++)
{
if (sep && (i != 0))
@@ -403,5 +432,6 @@
}
BIO_printf(out, "\n");
}
+ return 0;
}
Index: crypto/bio/bio.h
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/bio/bio.h,v
retrieving revision 1.56
diff -u -r1.56 bio.h
--- crypto/bio/bio.h 2002/01/24 16:20:17 1.56
+++ crypto/bio/bio.h 2002/04/29 14:44:58
@@ -647,6 +647,7 @@
#define BIO_F_CONN_CTRL 127
#define BIO_F_CONN_STATE 115
#define BIO_F_FILE_CTRL 116
+#define BIO_F_FILE_READ 130
#define BIO_F_LINEBUFFER_CTRL 129
#define BIO_F_MEM_READ 128
#define BIO_F_MEM_WRITE 117
Index: crypto/bio/bio_err.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/bio/bio_err.c,v
retrieving revision 1.19
diff -u -r1.19 bio_err.c
--- crypto/bio/bio_err.c 2002/01/22 22:29:39 1.19
+++ crypto/bio/bio_err.c 2002/04/29 14:44:58
@@ -91,6 +91,7 @@
{ERR_PACK(0,BIO_F_CONN_CTRL,0), "CONN_CTRL"},
{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
+{ERR_PACK(0,BIO_F_FILE_READ,0), "FILE_READ"},
{ERR_PACK(0,BIO_F_LINEBUFFER_CTRL,0), "LINEBUFFER_CTRL"},
{ERR_PACK(0,BIO_F_MEM_READ,0), "MEM_READ"},
{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
Index: crypto/bio/bss_file.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/bio/bss_file.c,v
retrieving revision 1.14
diff -u -r1.14 bss_file.c
--- crypto/bio/bss_file.c 2002/01/24 16:15:00 1.14
+++ crypto/bio/bss_file.c 2002/04/29 14:44:59
@@ -162,6 +162,12 @@
if (b->init && (out != NULL))
{
ret=fread(out,1,(int)outl,(FILE *)b->ptr);
+ if(ret == 0 && ferror((FILE *)b->ptr))
+ {
+ SYSerr(SYS_F_FREAD,get_last_sys_error());
+ BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
+ ret=-1;
+ }
}
return(ret);
}
Index: crypto/err/err.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/err/err.c,v
retrieving revision 1.51.2.1
diff -u -r1.51.2.1 err.c
--- crypto/err/err.c 2002/02/14 13:42:33 1.51.2.1
+++ crypto/err/err.c 2002/04/29 14:45:01
@@ -166,6 +166,7 @@
{ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
#endif
{ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
+ {ERR_PACK(0,SYS_F_FREAD,0), "fread"},
{0,NULL},
};
Index: crypto/err/err.h
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/err/err.h,v
retrieving revision 1.35.2.1
diff -u -r1.35.2.1 err.h
--- crypto/err/err.h 2002/04/22 13:55:37 1.35.2.1
+++ crypto/err/err.h 2002/04/29 14:45:01
@@ -182,6 +182,7 @@
#define SYS_F_ACCEPT 8
#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
#define SYS_F_OPENDIR 10
+#define SYS_F_FREAD 11
/* reasons */