Fix seg fault in s_time

Passing a negative value for the "-time" option to s_time results in a seg
fault. This commit fixes it so that time has to be greater than 0.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(cherry picked from commit dfef52f6f277327e118fdd0fe34486852c2789b6)
This commit is contained in:
Matt Caswell 2015-03-12 16:42:55 +00:00
parent f08731cd82
commit 6a43243d1d

View File

@ -302,6 +302,10 @@ static int parseArgs(int argc, char **argv)
if (--argc < 1) if (--argc < 1)
goto bad; goto bad;
maxTime = atoi(*(++argv)); maxTime = atoi(*(++argv));
if(maxTime <= 0) {
BIO_printf(bio_err, "time must be > 0\n");
badop = 1;
}
} else { } else {
BIO_printf(bio_err, "unknown option %s\n", *argv); BIO_printf(bio_err, "unknown option %s\n", *argv);
badop = 1; badop = 1;
@ -550,7 +554,8 @@ int MAIN(int argc, char **argv)
nConn, totalTime, ((double)nConn / totalTime), bytes_read); nConn, totalTime, ((double)nConn / totalTime), bytes_read);
printf printf
("%d connections in %ld real seconds, %ld bytes read per connection\n", ("%d connections in %ld real seconds, %ld bytes read per connection\n",
nConn, (long)time(NULL) - finishtime + maxTime, bytes_read / nConn); nConn, (long)time(NULL) - finishtime + maxTime,
bytes_read / (nConn?nConn:1));
ret = 0; ret = 0;
end: end: