From nobody@FreeBSD.org  Wed Oct 10 11:11:02 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 69741693
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:11:02 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 523FE8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:11:02 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9ABB2gk021403
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 11:11:02 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9ABB21Q021402;
	Wed, 10 Oct 2012 11:11:02 GMT
	(envelope-from nobody)
Message-Id: <201210101111.q9ABB21Q021402@red.freebsd.org>
Date: Wed, 10 Oct 2012 11:11:02 GMT
From: Erik Cederstrand <erik@cederstrand.dk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Fix div-by-zero in openssl
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         172569
>Category:       kern
>Synopsis:       [openssl] [patch] Fix div-by-zero in openssl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    benl
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 10 11:20:01 UTC 2012
>Closed-Date:    
>Last-Modified:  Wed Mar 27 01:54:40 UTC 2013
>Originator:     Erik Cederstrand
>Release:        CURRENT
>Organization:
>Environment:
>Description:
Fix an (extremely unlikely) divide-by-zero in openssl, found by Clang Analyzer: http://scan.freebsd.your.org/freebsd-head/LATEST/secure/report-jo4Joj.html#EndPath

This can only happen if the process is stalled for more than SECONDS seconds (currently 30) between lines 397 and 401.

Fix an identical case while there.
>How-To-Repeat:

>Fix:
See patch

Patch attached with submission follows:

Index: head/crypto/openssl/apps/s_time.c
===================================================================
--- head/crypto/openssl/apps/s_time.c	(revision 241370)
+++ head/crypto/openssl/apps/s_time.c	(working copy)
@@ -449,6 +449,10 @@
 		}
 	totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
 
+	if (nConn == 0) {
+		fprintf( stderr, "Unable to get any connections\n" );
+		goto end;
+	}
 	i=(int)((long)time(NULL)-finishtime+maxTime);
 	printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
 	printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
@@ -540,6 +544,10 @@
 	totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
 
 
+	if (nConn == 0) {
+		fprintf( stderr, "Unable to get any connections\n" );
+		goto end;
+	}
 	printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
 	printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jkim 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Mar 10 02:57:09 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172569 
Responsible-Changed-From-To: jkim->benl 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Mar 27 01:53:45 UTC 2013 
Responsible-Changed-Why:  
Over to new openssl maintainer. 

Requested by:	jkim 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172569 
>Unformatted:
