From c6f1787bbd8012b372158c15ac84abf75261be3e Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Thu, 19 Oct 2000 08:03:14 +0000 Subject: [PATCH] NCONF_get_number() has no error checking at all. As a replacement, NCONF_get_number_e() is defined (_e for "error checking") and is promoted strongly. The old NCONF_get_number is kept around for binary backward compatibility. --- crypto/conf/conf.h | 11 +++++++- crypto/conf/conf_api.c | 4 +++ crypto/conf/conf_err.c | 2 ++ crypto/conf/conf_lib.c | 58 ++++++++++++++++++++++++++++++++---------- 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/crypto/conf/conf.h b/crypto/conf/conf.h index cd40a0db21..3fded162a2 100644 --- a/crypto/conf/conf.h +++ b/crypto/conf/conf.h @@ -136,10 +136,17 @@ int NCONF_load_fp(CONF *conf, FILE *fp,long *eline); int NCONF_load_bio(CONF *conf, BIO *bp,long *eline); STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section); char *NCONF_get_string(CONF *conf,char *group,char *name); -long NCONF_get_number(CONF *conf,char *group,char *name); +int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result); int NCONF_dump_fp(CONF *conf, FILE *out); int NCONF_dump_bio(CONF *conf, BIO *out); +#if 0 /* The following function has no error checking, + and should therefore be avoided */ +long NCONF_get_number(CONF *conf,char *group,char *name); +#else +#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r); +#endif + /* BEGIN ERROR CODES */ /* The following lines are auto generated by the script mkerr.pl. Any changes @@ -156,6 +163,7 @@ int NCONF_dump_bio(CONF *conf, BIO *out); #define CONF_F_NCONF_DUMP_BIO 105 #define CONF_F_NCONF_DUMP_FP 106 #define CONF_F_NCONF_GET_NUMBER 107 +#define CONF_F_NCONF_GET_NUMBER_E 112 #define CONF_F_NCONF_GET_SECTION 108 #define CONF_F_NCONF_GET_STRING 109 #define CONF_F_NCONF_LOAD_BIO 110 @@ -169,6 +177,7 @@ int NCONF_dump_bio(CONF *conf, BIO *out); #define CONF_R_NO_CONF 105 #define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106 #define CONF_R_NO_SECTION 107 +#define CONF_R_NO_VALUE 108 #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 #define CONF_R_VARIABLE_HAS_NO_VALUE 104 diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c index d05a778ff6..7abeeced07 100644 --- a/crypto/conf/conf_api.c +++ b/crypto/conf/conf_api.c @@ -153,6 +153,9 @@ char *_CONF_get_string(CONF *conf, char *section, char *name) return(Getenv(name)); } +#if 0 /* There's no way to provide error checking with this function, so + force implementors of the higher levels to get a string and read + the number themselves. */ long _CONF_get_number(CONF *conf, char *section, char *name) { char *str; @@ -169,6 +172,7 @@ long _CONF_get_number(CONF *conf, char *section, char *name) str++; } } +#endif int _CONF_new_data(CONF *conf) { diff --git a/crypto/conf/conf_err.c b/crypto/conf/conf_err.c index 8c2bc6f1c4..c3766d2886 100644 --- a/crypto/conf/conf_err.c +++ b/crypto/conf/conf_err.c @@ -73,6 +73,7 @@ static ERR_STRING_DATA CONF_str_functs[]= {ERR_PACK(0,CONF_F_NCONF_DUMP_BIO,0), "NCONF_dump_bio"}, {ERR_PACK(0,CONF_F_NCONF_DUMP_FP,0), "NCONF_dump_fp"}, {ERR_PACK(0,CONF_F_NCONF_GET_NUMBER,0), "NCONF_get_number"}, +{ERR_PACK(0,CONF_F_NCONF_GET_NUMBER_E,0), "NCONF_get_number_e"}, {ERR_PACK(0,CONF_F_NCONF_GET_SECTION,0), "NCONF_get_section"}, {ERR_PACK(0,CONF_F_NCONF_GET_STRING,0), "NCONF_get_string"}, {ERR_PACK(0,CONF_F_NCONF_LOAD_BIO,0), "NCONF_load_bio"}, @@ -89,6 +90,7 @@ static ERR_STRING_DATA CONF_str_reasons[]= {CONF_R_NO_CONF ,"no conf"}, {CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE ,"no conf or environment variable"}, {CONF_R_NO_SECTION ,"no section"}, +{CONF_R_NO_VALUE ,"no value"}, {CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, {CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, {0,NULL} diff --git a/crypto/conf/conf_lib.c b/crypto/conf/conf_lib.c index 51bd0db655..a1d31cf953 100644 --- a/crypto/conf/conf_lib.c +++ b/crypto/conf/conf_lib.c @@ -156,13 +156,21 @@ char *CONF_get_string(LHASH *conf,char *group,char *name) long CONF_get_number(LHASH *conf,char *group,char *name) { CONF ctmp; + int status; + long result = 0; if (default_CONF_method == NULL) default_CONF_method = NCONF_default(); default_CONF_method->init(&ctmp); ctmp.data = conf; - return NCONF_get_number(&ctmp, group, name); + status = NCONF_get_number_e(&ctmp, group, name, &result); + if (status == 0) + { + /* This function does not believe in errors... */ + ERR_get_error(); + } + return result; } void CONF_free(LHASH *conf) @@ -322,25 +330,33 @@ char *NCONF_get_string(CONF *conf,char *group,char *name) CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); return NULL; } + CONFerr(CONF_F_NCONF_GET_STRING, + CONF_R_NO_VALUE); return NULL; } -long NCONF_get_number(CONF *conf,char *group,char *name) +int NCONF_get_number_e(CONF *conf,char *group,char *name,long *result) { -#if 0 /* As with _CONF_get_string(), we rely on the possibility of finding - an environment variable with a suitable name. Unfortunately, there's - no way with the current API to see if we found one or not... - The meaning of this is that if a number is not found anywhere, it - will always default to 0. */ - if (conf == NULL) + char *str; + + if (result == NULL) { - CONFerr(CONF_F_NCONF_GET_NUMBER, - CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); + CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER); return 0; } -#endif - - return _CONF_get_number(conf, group, name); + + str = NCONF_get_string(conf,group,name); + + if (str == NULL) + return 0; + + for (;conf->meth->is_number(conf, *str);) + { + *result = (*result)*10 + conf->meth->to_int(conf, *str); + str++; + } + + return 1; } #ifndef NO_FP_API @@ -369,3 +385,19 @@ int NCONF_dump_bio(CONF *conf, BIO *out) return conf->meth->dump(conf, out); } +/* This function should be avoided */ +#undef NCONF_get_number +long NCONF_get_number(CONF *conf,char *group,char *name) + { + int status; + long ret=0; + + status = NCONF_get_number_e(conf, group, name, &ret); + if (status == 0) + { + /* This function does not believe in errors... */ + ERR_get_error(); + } + return ret; + } +