ECC-748: grib_get/bufr_get: infinite loop when a directory is passed in

This commit is contained in:
Shahram Najm 2018-09-07 16:49:40 +01:00
parent cb2381ccb8
commit 47accafef5
12 changed files with 24 additions and 24 deletions

View File

@ -400,6 +400,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -88,6 +88,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -71,6 +71,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -82,14 +82,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
struct stat s;
int stat_val = stat(file->name, &s);
if ( stat_val == 0 ) {
if (S_ISDIR(s.st_mode)) {
fprintf(stderr, "ERROR: \"%s\": Is a directory\n", file->name);
exit(1);
}
}
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -92,6 +92,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -125,6 +125,8 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil
if (!options->current_infile->name) return 0;
if (json) return 0;
exit_if_input_is_directory(file->name);
sprintf(tmp,"FILE: %s ",options->current_infile->name);
if (!grib_options_on("C"))
fprintf(stdout,"***** %s\n",tmp);

View File

@ -66,14 +66,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
struct stat s;
int stat_val = stat(file->name, &s);
if ( stat_val == 0 ) {
if (S_ISDIR(s.st_mode)) {
fprintf(stderr, "ERROR: \"%s\": Is a directory\n", file->name);
exit(1);
}
}
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -160,6 +160,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -67,6 +67,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -193,14 +193,7 @@ int grib_tool_new_filename_action(grib_runtime_options* options,const char* file
int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* file)
{
struct stat s;
int stat_val = stat(file->name, &s);
if ( stat_val == 0 ) {
if (S_ISDIR(s.st_mode)) {
fprintf(stderr, "ERROR: \"%s\": Is a directory\n", file->name);
exit(1);
}
}
exit_if_input_is_directory(file->name);
return 0;
}

View File

@ -1112,3 +1112,15 @@ void grib_tools_write_message(grib_runtime_options* options, grib_handle* h)
#endif
}
int exit_if_input_is_directory(const char* filename)
{
struct stat s;
int stat_val = stat(filename, &s);
if ( stat_val == 0 ) {
if (S_ISDIR(s.st_mode)) {
fprintf(stderr, "ERROR: \"%s\": Is a directory\n", filename);
exit(1);
}
}
return 0;
}

View File

@ -199,6 +199,7 @@ int grib_process_runtime_options(grib_context* c,int argc,char** argv,grib_runti
void grib_tools_write_message(grib_runtime_options* options, grib_handle* h);
int grib_tool_new_filename_action(grib_runtime_options* options,const char* file);
int grib_no_handle_action(grib_runtime_options* options,int err);
int exit_if_input_is_directory(const char* filename);
#endif