Guard against buffer overrun

This commit is contained in:
Shahram Najm 2018-08-07 15:16:50 +01:00
parent 7c38b300e2
commit 148604189e
1 changed files with 5 additions and 1 deletions

View File

@ -27,7 +27,7 @@
const char* grib_tool_description = "Convert a GRIB file to netCDF format.";
const char* grib_tool_name = "grib_to_netcdf";
const char* grib_tool_usage = "[options] grib_file grib_file ... ";
static char argvString[2048];
static char argvString[2048] = {0,};
/*=====================================================================*/
@ -3978,7 +3978,11 @@ int main(int argc, char *argv[])
int i, ret = 0;
/* GRIB-413: Collect all program arguments into a string */
const size_t maxLen = sizeof(argvString);
size_t currLen = 0;
for (i=0; i<argc; ++i) {
currLen += strlen(argv[i]);
if ( currLen >= maxLen-1 ) break;
strcat(argvString, argv[i]);
if (i != argc-1) strcat(argvString, " ");
}