Reproduced on Windows 7 (likely on the all old versions)
I use OpenSSL v. 0.9.8k but I has looked the last version and the bug also 
exist.

When we try call OPENSSL_cinfig with the path who specifies on the DvD(or 
CD)-ROM without disc the openSSL is exiting.

It happens because in the function
(version 0.9.8k): .\crypto\bio\bss_file.c

BIO *BIO_new_file(const char *filename, const char *mode)
                {
                BIO *ret;
                FILE *file;

                if ((file=fopen(filename,mode)) == NULL) 
<------------------------
                                {
                                SYSerr(SYS_F_FOPEN,get_last_sys_error());
                                
ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");

                                if (errno == ENOENT) <------------------------ 
errno == EACCES
                                                
BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
                                else
                                                
BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); <----------------------
                                return(NULL);
                                }
                if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
                                {
                                fclose(file);
                                return(NULL);
                                }

                BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we 
disengage UPLINK */
                BIO_set_fp(ret,file,BIO_CLOSE);
                return(ret);
                }

The function fopen() returns EACCESS instead of ENOENT if it passes path to 
DVD-ROM without disc.
You can check it:

                // C:\ - logical disc exists
                FILE * f1 = fopen("C:\\test.fl", "rb");
                int myErrno = errno;                                       // 2 
- ENOENT

                // D:\ - logical disc not exists
                f1 = fopen("D:\\test.fl", "rb");
                myErrno = errno;                                             // 
2 - ENOENT

                // N:\ - DVD-ROM without dvd-disk
                f1 = fopen("N:\\test.fl", "rb");
                myErrno = errno;                                             // 
13 - EACCES

Because of this is calling BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); and at the 
end the OPENSSL_config do call exit(1).

void OPENSSL_config(const char *config_name)
{
...
       ERR_clear_error();
       if (CONF_modules_load_file(NULL, config_name,
       CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
              {
              BIO *bio_err;
              ERR_load_crypto_strings();
              if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)
                     {
                     BIO_printf(bio_err,"Auto configuration failed\n");
                     ERR_print_errors(bio_err);
                     BIO_free(bio_err);
                     }
              exit(1); <-------------------------
              }

       return;
}

For my project I changed the source of OpenSSL:

BIO *BIO_new_file(const char *filename, const char *mode)
       {
       BIO *ret;
       FILE *file;

       if ((file=fopen(filename,mode)) == NULL)
              {
              SYSerr(SYS_F_FOPEN,get_last_sys_error());
              ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");

              if (errno == ENOENT || errno == EACCES)
                     BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
              else
                     BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
              return(NULL);
              }

Now it's working good if the path to openssl.cnf will be not correctly.


Best Regards,
Roman Sergeev
Software Engineer

EPAM Systems
Saratov office, Russia

E-mail:    [email protected]<mailto:[email protected]>
http://www.epam.com<https://owamsq.epam.com/exchweb/bin/redir.asp?URL=http://www.epam.com/>


Reproduced on Windows 7 (likely on the all old versions)

I use OpenSSL v. 0.9.8k but I has looked the last version and the bug also exist.

 

When we try call OPENSSL_cinfig with the path who specifies on the DvD(or CD)-ROM without disc the openSSL is exiting.

 

It happens because in the function

(version 0.9.8k): .\crypto\bio\bss_file.c

 

BIO *BIO_new_file(const char *filename, const char *mode)

                {

                BIO *ret;

                FILE *file;

 

                if ((file=fopen(filename,mode)) == NULL) ?----------------------

                                {

                                SYSerr(SYS_F_FOPEN,get_last_sys_error());

                                ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");

 

                                if (errno == ENOENT) ?---------------------- errno == EACCES

                                                BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);

                                else

                                                BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); ?--------------------

                                return(NULL);

                                }

                if ((ret=BIO_new(BIO_s_file_internal())) == NULL)

                                {

                                fclose(file);

                                return(NULL);

                                }

 

                BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */

                BIO_set_fp(ret,file,BIO_CLOSE);

                return(ret);

                }

 

The function fopen() returns EACCESS instead of ENOENT if it passes path to DVD-ROM without disc.

You can check it:

 

                // C:\ - logical disc exists

                FILE * f1 = fopen("C:\\test.fl", "rb");

                int myErrno = errno;                                       // 2 - ENOENT

 

                // D:\ - logical disc not exists

                f1 = fopen("D:\\test.fl", "rb");

                myErrno = errno;                                             // 2 - ENOENT

 

                // N:\ - DVD-ROM without dvd-disk

                f1 = fopen("N:\\test.fl", "rb");

                myErrno = errno;                                             // 13 – EACCES

 

Because of this is calling BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); and at the end the OPENSSL_config do call exit(1).

 

void OPENSSL_config(const char *config_name)

{

       ERR_clear_error();

       if (CONF_modules_load_file(NULL, config_name,

       CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)

              {

              BIO *bio_err;

              ERR_load_crypto_strings();

              if ((bio_err=BIO_new_fp(stderr, BIO_NOCLOSE)) != NULL)

                     {

                     BIO_printf(bio_err,"Auto configuration failed\n");

                     ERR_print_errors(bio_err);

                     BIO_free(bio_err);

                     }

              exit(1); ?-----------------------

              }

 

       return;

}

 

For my project I changed the source of OpenSSL:

 

BIO *BIO_new_file(const char *filename, const char *mode)

       {

       BIO *ret;

       FILE *file;

 

       if ((file=fopen(filename,mode)) == NULL)

              {

              SYSerr(SYS_F_FOPEN,get_last_sys_error());

              ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");

 

              if (errno == ENOENT || errno == EACCES)

                     BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);

              else

                     BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);

              return(NULL);

              }

 

Now it’s working good if the path to openssl.cnf will be not correctly.

 

 

Best Regards,
Roman Sergeev

Software Engineer


EPAM Systems
Saratov
office, Russia

E-mail:
    [email protected]
http://www.epam.com

 

Reply via email to