@@ -1173,6 +1173,7 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
11731173 FILE * file ;
11741174 size_t nread ;
11751175 char * full_content = NULL ;
1176+ char * full_content_tmp_ptr = NULL ;
11761177 size_t total_lenght = 0 ;
11771178 msre_var * rvar = NULL ;
11781179
@@ -1182,19 +1183,23 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
11821183 continue ;
11831184 }
11841185
1186+ full_content = (char * )apr_pcalloc (mptmp , (sizeof (char )* parts [i ]-> length ) + 1 );
1187+ if (full_content == NULL ) {
1188+ if (msr -> txcfg -> debuglog_level >= 3 ) {
1189+ msr_log (msr , 3 , "Variable FILES_TMP_CONTENT will not be created, not " \
1190+ "enough memory available." );
1191+ }
1192+ goto files_tmp_content_not_enough_mem ;
1193+ }
1194+ full_content_tmp_ptr = full_content ;
1195+
11851196 while ((nread = fread (buf , 1 , 1023 , file )) > 0 )
11861197 {
1187- total_lenght += nread ;
1188- buf [nread ] = '\0' ;
1189- if (full_content == NULL )
1190- {
1191- full_content = apr_psprintf (mptmp , "%s" , buf );
1192- }
1193- else
1194- {
1195- full_content = apr_psprintf (mptmp , "%s%s" , full_content , buf );
1196- }
1198+ full_content_tmp_ptr = memcpy (full_content_tmp_ptr , buf , nread );
1199+ full_content_tmp_ptr += nread ;
1200+ total_lenght += nread ;
11971201 }
1202+ full_content_tmp_ptr [total_lenght ] = '\0' ;
11981203 fclose (file );
11991204
12001205 rvar = apr_pmemdup (mptmp , var , sizeof (msre_var ));
@@ -1209,6 +1214,7 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
12091214 }
12101215 }
12111216
1217+ files_tmp_content_not_enough_mem :
12121218 return count ;
12131219}
12141220
0 commit comments