@@ -38,6 +38,9 @@ namespace
3838DbgCtl dbg_ctl_cache_hosting{" cache_hosting" };
3939DbgCtl dbg_ctl_matcher{" matcher" };
4040
41+ // Use same constant as defined in traffic_cache_tool/CacheDefs.h
42+ constexpr static int MAX_VOLUME_IDX = 255 ;
43+
4144} // end anonymous namespace
4245
4346/* ************************************************************
@@ -227,6 +230,22 @@ CacheHostTable::Match(std::string_view rdata, CacheHostResult *result) const
227230 hostMatch->Match (rdata, result);
228231}
229232
233+ CacheVol *
234+ CacheHostTable::getVolumeByNumber (int volume_num) const
235+ {
236+ if (volume_num < 1 || volume_num > MAX_VOLUME_IDX) {
237+ return nullptr ;
238+ }
239+
240+ for (int i = 0 ; i < gen_host_rec.num_cachevols ; i++) {
241+ if (gen_host_rec.cp [i] && gen_host_rec.cp [i]->vol_number == volume_num) {
242+ return gen_host_rec.cp [i];
243+ }
244+ }
245+
246+ return nullptr ;
247+ }
248+
230249int
231250CacheHostTable::config_callback (const char * /* name ATS_UNUSED */ , RecDataT /* data_type ATS_UNUSED */ ,
232251 RecData /* data ATS_UNUSED */ , void *cookie)
@@ -614,6 +633,17 @@ ConfigVolumes::read_config_file()
614633 return ;
615634}
616635
636+ bool
637+ ConfigVolumes::volume_number_exists (int vol_number) const
638+ {
639+ for (ConfigVol *config_vol = cp_queue.head ; config_vol; config_vol = config_vol->link .next ) {
640+ if (config_vol->number == vol_number) {
641+ return true ;
642+ }
643+ }
644+ return false ;
645+ }
646+
617647void
618648ConfigVolumes::BuildListFromString (char *config_file_path, char *file_buf)
619649{
@@ -698,7 +728,7 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
698728 break ;
699729 }
700730
701- if (volume_number < 1 || volume_number > 255 ) {
731+ if (volume_number < 1 || volume_number > MAX_VOLUME_IDX ) {
702732 err = " Bad Volume Number" ;
703733 break ;
704734 }
@@ -742,8 +772,12 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
742772 in_percent = 0 ;
743773 }
744774 } else if (strcasecmp (tmp, " avg_obj_size" ) == 0 ) { // match avg_obj_size
745- tmp += 13 ;
746- avg_obj_size = static_cast <int >(ink_atoi64 (tmp));
775+ tmp += 13 ;
776+ if (!ParseRules::is_digit (*tmp)) {
777+ err = " Invalid avg_obj_size value (must start with a number, e.g., 64K)" ;
778+ break ;
779+ }
780+ avg_obj_size = static_cast <int >(ink_atoi64 (tmp));
747781
748782 if (avg_obj_size < 0 ) {
749783 err = " Invalid avg_obj_size value (must be >= 0)" ;
@@ -753,8 +787,12 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
753787 tmp++;
754788 }
755789 } else if (strcasecmp (tmp, " fragment_size" ) == 0 ) { // match fragment_size
756- tmp += 14 ;
757- fragment_size = static_cast <int >(ink_atoi64 (tmp));
790+ tmp += 14 ;
791+ if (!ParseRules::is_digit (*tmp)) {
792+ err = " Invalid fragment_size value (must start with a number, e.g., 1M)" ;
793+ break ;
794+ }
795+ fragment_size = static_cast <int >(ink_atoi64 (tmp));
758796
759797 if (fragment_size < 0 ) {
760798 err = " Invalid fragment_size value (must be >= 0)" ;
@@ -776,8 +814,12 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
776814 break ;
777815 }
778816 } else if (strcasecmp (tmp, " ram_cache_size" ) == 0 ) { // match ram_cache_size
779- tmp += 15 ;
780- ram_cache_size = ink_atoi64 (tmp);
817+ tmp += 15 ;
818+ if (!ParseRules::is_digit (*tmp)) {
819+ err = " Invalid ram_cache_size value (must start with a number, e.g., 10G)" ;
820+ break ;
821+ }
822+ ram_cache_size = ink_atoi64 (tmp);
781823
782824 if (ram_cache_size < 0 ) {
783825 err = " Invalid ram_cache_size value (must be >= 0)" ;
@@ -788,8 +830,12 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
788830 tmp++;
789831 }
790832 } else if (strcasecmp (tmp, " ram_cache_cutoff" ) == 0 ) { // match ram_cache_cutoff
791- tmp += 17 ;
792- ram_cache_cutoff = ink_atoi64 (tmp);
833+ tmp += 17 ;
834+ if (!ParseRules::is_digit (*tmp)) {
835+ err = " Invalid ram_cache_cutoff value (must start with a number, e.g., 5M)" ;
836+ break ;
837+ }
838+ ram_cache_cutoff = ink_atoi64 (tmp);
793839
794840 if (ram_cache_cutoff < 0 ) {
795841 err = " Invalid ram_cache_cutoff value (must be >= 0)" ;
@@ -802,7 +848,7 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
802848
803849 // ends here
804850 if (end < line_end) {
805- tmp++ ;
851+ tmp = line_end ;
806852 }
807853 }
808854
0 commit comments