@@ -711,7 +711,8 @@ char* addResourceAttr(ngx_conf_t* cf, ngx_command_t* cmd, void* conf)
711711 return NGX_CONF_OK;
712712}
713713
714- char * setTrustedCertificate (ngx_conf_t * cf, ngx_command_t * cmd, void * conf) {
714+ char * setTrustedCertificate (ngx_conf_t * cf, ngx_command_t * cmd, void * conf)
715+ {
715716 auto path = ((ngx_str_t *)cf->args ->elts )[1 ];
716717 auto mcf = getMainConf (cf);
717718
@@ -727,11 +728,13 @@ char* setTrustedCertificate(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
727728 return (char *)NGX_CONF_ERROR;
728729 }
729730 file.exceptions (std::ios::failbit | std::ios::badbit);
730- file.seekg ( 0 , std::ios::end);
731- size_t size = file. tellg ();
732- mcf-> trustedCert . resize (size );
731+ file.peek (); // trigger early error for dirs
732+
733+ size_t size = file. seekg ( 0 , std::ios::end). tellg ( );
733734 file.seekg (0 );
734- file.read (&mcf->trustedCert [0 ], mcf->trustedCert .size ());
735+
736+ mcf->trustedCert .resize (size);
737+ file.read (&mcf->trustedCert [0 ], size);
735738 } catch (const std::exception& e) {
736739 ngx_conf_log_error (NGX_LOG_EMERG, cf, 0 ,
737740 " failed to read \" %V\" : %s" , &path, e.what ());
0 commit comments