Guard against buffer overrun
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, " ");
}
