mirror of https://github.com/ecmwf/eccodes.git
ECC-748: grib_get/bufr_get: infinite loop when a directory is passed in
This commit is contained in:
parent
cb2381ccb8
commit
47accafef5
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue