From 3002674bacbbaeecf91318fe5170df1f9ca1ccf4 Mon Sep 17 00:00:00 2001 From: Lucas Pardue Date: Tue, 1 Sep 2015 17:13:51 +0000 Subject: [PATCH] h2load: Improve checking for timing script imput, prevent false positive in certain situations --- src/h2load.cc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 3f37adc3..eeb1d1f6 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -1164,9 +1164,14 @@ void read_script_from_file(std::istream &infile, char *end; auto v = std::strtod(start, &end); - if (end == start || errno != 0) { + errno = 0; + if (v < 0.0 || !std::isfinite(v) || end == start || errno != 0) { + auto error = errno; std::cerr << "Time value error at line " << line_count << ". \n\t" - << script_line.substr(0, pos) << std::endl; + << "value = " << script_line.substr(0, pos) << std::endl; + if (error != 0) { + std::cerr << "\t" << strerror(error) << std::endl; + } exit(EXIT_FAILURE); } @@ -1295,15 +1300,15 @@ Options: Path of a file containing one or more lines separated by EOLs. Each script line is composed of two tab-separated fields. The first field represents the time offset from - the start of execution, expressed as milliseconds with - microsecond resolution. The second field represents the - URI. This option will disable URIs getting from - command-line. If '-' is given as , script lines - will be read from stdin. Script lines are used in order - for each client. If -n is given, it must be less than - or equal to the number of script lines, larger values are - clamped to the number of script lines. If -n is - not given, the number of requests will default to the + the start of execution, expressed as a positive value of + milliseconds with microsecond resolution. The second + field represents the URI. This option will disable URIs + getting from command-line. If '-' is given as , + script lines will be read from stdin. Script lines are + used in order for each client. If -n is given, it must be + less than or equal to the number of script lines, larger + values are clamped to the number of script lines. If -n + is not given, the number of requests will default to the number of script lines. The scheme, host and port defined in the first URI are used solely. Values contained in other URIs, if present, are ignored. Definition of a