@@ -484,19 +484,13 @@ static bool config_file_parse_line(config_file_t *conf,
484484 if (!path )
485485 return false;
486486
487- if (string_is_empty (path ))
487+ if ( string_is_empty (path )
488+ || conf -> include_depth >= MAX_INCLUDE_DEPTH )
488489 {
489490 free (path );
490491 return false;
491492 }
492493
493- if (conf -> include_depth >= MAX_INCLUDE_DEPTH )
494- {
495- fprintf (stderr , "!!! #include depth exceeded for config. Might be a cycle.\n" );
496- free (path );
497- return false;
498- }
499-
500494 real_path [0 ] = '\0' ;
501495 config_file_add_sub_conf (conf , path ,
502496 real_path , sizeof (real_path ), cb );
@@ -795,7 +789,7 @@ config_file_t *config_file_new_alloc(void)
795789 return conf ;
796790}
797791
798- struct config_entry_list * config_get_entry (
792+ static struct config_entry_list * config_get_entry_internal (
799793 const config_file_t * conf ,
800794 const char * key , struct config_entry_list * * prev )
801795{
@@ -816,9 +810,22 @@ struct config_entry_list *config_get_entry(
816810 return NULL ;
817811}
818812
813+ struct config_entry_list * config_get_entry (
814+ const config_file_t * conf , const char * key )
815+ {
816+ struct config_entry_list * entry = NULL ;
817+ for (entry = conf -> entries ; entry ; entry = entry -> next )
818+ {
819+ if (string_is_equal (key , entry -> key ))
820+ return entry ;
821+ }
822+ return NULL ;
823+ }
824+
825+
819826bool config_get_double (config_file_t * conf , const char * key , double * in )
820827{
821- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
828+ const struct config_entry_list * entry = config_get_entry (conf , key );
822829
823830 if (!entry )
824831 return false;
@@ -829,7 +836,7 @@ bool config_get_double(config_file_t *conf, const char *key, double *in)
829836
830837bool config_get_float (config_file_t * conf , const char * key , float * in )
831838{
832- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
839+ const struct config_entry_list * entry = config_get_entry (conf , key );
833840
834841 if (!entry )
835842 return false;
@@ -841,7 +848,7 @@ bool config_get_float(config_file_t *conf, const char *key, float *in)
841848
842849bool config_get_int (config_file_t * conf , const char * key , int * in )
843850{
844- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
851+ const struct config_entry_list * entry = config_get_entry (conf , key );
845852 errno = 0 ;
846853
847854 if (entry )
@@ -860,7 +867,7 @@ bool config_get_int(config_file_t *conf, const char *key, int *in)
860867
861868bool config_get_size_t (config_file_t * conf , const char * key , size_t * in )
862869{
863- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
870+ const struct config_entry_list * entry = config_get_entry (conf , key );
864871 errno = 0 ;
865872
866873 if (entry )
@@ -879,7 +886,7 @@ bool config_get_size_t(config_file_t *conf, const char *key, size_t *in)
879886#if defined(__STDC_VERSION__ ) && __STDC_VERSION__ >=199901L
880887bool config_get_uint64 (config_file_t * conf , const char * key , uint64_t * in )
881888{
882- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
889+ const struct config_entry_list * entry = config_get_entry (conf , key );
883890 errno = 0 ;
884891
885892 if (entry )
@@ -898,7 +905,7 @@ bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
898905
899906bool config_get_uint (config_file_t * conf , const char * key , unsigned * in )
900907{
901- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
908+ const struct config_entry_list * entry = config_get_entry (conf , key );
902909 errno = 0 ;
903910
904911 if (entry )
@@ -917,7 +924,7 @@ bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
917924
918925bool config_get_hex (config_file_t * conf , const char * key , unsigned * in )
919926{
920- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
927+ const struct config_entry_list * entry = config_get_entry (conf , key );
921928 errno = 0 ;
922929
923930 if (entry )
@@ -936,7 +943,7 @@ bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
936943
937944bool config_get_char (config_file_t * conf , const char * key , char * in )
938945{
939- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
946+ const struct config_entry_list * entry = config_get_entry (conf , key );
940947
941948 if (entry )
942949 {
@@ -952,7 +959,7 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
952959
953960bool config_get_string (config_file_t * conf , const char * key , char * * str )
954961{
955- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
962+ const struct config_entry_list * entry = config_get_entry (conf , key );
956963
957964 if (!entry || !entry -> value )
958965 return false;
@@ -971,8 +978,7 @@ bool config_get_config_path(config_file_t *conf, char *s, size_t len)
971978bool config_get_array (config_file_t * conf , const char * key ,
972979 char * buf , size_t size )
973980{
974- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
975-
981+ const struct config_entry_list * entry = config_get_entry (conf , key );
976982 if (entry )
977983 return strlcpy (buf , entry -> value , size ) < size ;
978984 return false;
@@ -985,7 +991,7 @@ bool config_get_path(config_file_t *conf, const char *key,
985991 if (config_get_array (conf , key , buf , size ))
986992 return true;
987993#else
988- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
994+ const struct config_entry_list * entry = config_get_entry (conf , key );
989995
990996 if (entry )
991997 {
@@ -998,23 +1004,31 @@ bool config_get_path(config_file_t *conf, const char *key,
9981004
9991005bool config_get_bool (config_file_t * conf , const char * key , bool * in )
10001006{
1001- const struct config_entry_list * entry = config_get_entry (conf , key , NULL );
1007+ const struct config_entry_list * entry = config_get_entry (conf , key );
10021008
1003- if (entry )
1004- {
1005- if (string_is_equal (entry -> value , "true" ))
1006- * in = true;
1007- else if (string_is_equal (entry -> value , "1" ))
1008- * in = true;
1009- else if (string_is_equal (entry -> value , "false" ))
1010- * in = false;
1011- else if (string_is_equal (entry -> value , "0" ))
1012- * in = false;
1013- else
1014- return false;
1015- }
1009+ if (!entry )
1010+ return false;
10161011
1017- return entry != NULL ;
1012+ if (
1013+ (
1014+ entry -> value [0 ] == '1'
1015+ && entry -> value [1 ] == '\0'
1016+ )
1017+ || string_is_equal (entry -> value , "true" )
1018+ )
1019+ * in = true;
1020+ else if (
1021+ (
1022+ entry -> value [0 ] == '0'
1023+ && entry -> value [1 ] == '\0'
1024+ )
1025+ || string_is_equal (entry -> value , "false" )
1026+ )
1027+ * in = false;
1028+ else
1029+ return false;
1030+
1031+ return true;
10181032}
10191033
10201034void config_set_string (config_file_t * conf , const char * key , const char * val )
@@ -1034,7 +1048,8 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
10341048 }
10351049 else
10361050 {
1037- entry = config_get_entry (conf , key , & last );
1051+ entry = config_get_entry_internal (
1052+ conf , key , & last );
10381053 if (entry )
10391054 {
10401055 /* An entry corresponding to 'key' already exists
@@ -1090,7 +1105,7 @@ void config_unset(config_file_t *conf, const char *key)
10901105 return ;
10911106
10921107 last = conf -> entries ;
1093- entry = config_get_entry (conf , key , & last );
1108+ entry = config_get_entry_internal (conf , key , & last );
10941109
10951110 if (!entry )
10961111 return ;
0 commit comments