@@ -1173,6 +1173,7 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
1173
1173
FILE * file ;
1174
1174
size_t nread ;
1175
1175
char * full_content = NULL ;
1176
+ char * full_content_tmp_ptr = NULL ;
1176
1177
size_t total_lenght = 0 ;
1177
1178
msre_var * rvar = NULL ;
1178
1179
@@ -1182,19 +1183,23 @@ static int var_files_tmp_contents_generate(modsec_rec *msr, msre_var *var,
1182
1183
continue ;
1183
1184
}
1184
1185
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
+
1185
1196
while ((nread = fread (buf , 1 , 1023 , file )) > 0 )
1186
1197
{
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 ;
1197
1201
}
1202
+ full_content_tmp_ptr [total_lenght ] = '\0' ;
1198
1203
fclose (file );
1199
1204
1200
1205
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,
1209
1214
}
1210
1215
}
1211
1216
1217
+ files_tmp_content_not_enough_mem :
1212
1218
return count ;
1213
1219
}
1214
1220
0 commit comments