From 461f00dd53cc1145cd26628db025b03f481f9201 Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Tue, 11 Jun 2002 11:41:26 +0000 Subject: [PATCH] Handle read failures better. --- CHANGES | 3 +++ apps/dgst.c | 56 +++++++++++++++++++++++++++++++++---------- crypto/bio/bio.h | 1 + crypto/bio/bio_err.c | 1 + crypto/bio/bss_file.c | 6 +++++ crypto/err/err.c | 1 + crypto/err/err.h | 1 + 7 files changed, 56 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index d63996c70d..715424be76 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,9 @@ Changes between 0.9.6d and 0.9.7 [XX xxx 2002] + *) Improve diagnostics in file reading and command-line digests. + [Ben Laurie aided and abetted by Solar Designer ] + *) Add AES modes CFB and OFB to the object database. Correct an error in AES-CFB decryption. [Richard Levitte] diff --git a/apps/dgst.c b/apps/dgst.c index 0620b32bb4..e21c3d83ac 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -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 @@ int MAIN(int argc, char **argv) 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 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 @@ void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, { BIO_printf(bio_err, "Error Signing Data\n"); ERR_print_errors(bio_err); - return; + return 1; } } else @@ -395,6 +423,7 @@ void do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, if(binout) BIO_write(out, buf, len); else { + BIO_write(out,title,strlen(title)); for (i=0; iinit && (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); } diff --git a/crypto/err/err.c b/crypto/err/err.c index 04773d65a6..5abe44e6d5 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -166,6 +166,7 @@ static ERR_STRING_DATA ERR_str_functs[]= {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}, }; diff --git a/crypto/err/err.h b/crypto/err/err.h index cc9bb649ea..988ef81aa0 100644 --- a/crypto/err/err.h +++ b/crypto/err/err.h @@ -182,6 +182,7 @@ typedef struct err_state_st #define SYS_F_ACCEPT 8 #define SYS_F_WSASTARTUP 9 /* Winsock stuff */ #define SYS_F_OPENDIR 10 +#define SYS_F_FREAD 11 /* reasons */ -- 2.25.1