From patchwork Fri Jan 25 06:42:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 2041351 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5BE32DF223 for ; Fri, 25 Jan 2013 06:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751292Ab3AYGnJ (ORCPT ); Fri, 25 Jan 2013 01:43:09 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:19416 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751259Ab3AYGnI (ORCPT ); Fri, 25 Jan 2013 01:43:08 -0500 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id r0P6h5Wp005305 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 25 Jan 2013 06:43:05 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0P6h4HO014635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 25 Jan 2013 06:43:04 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0P6h4n8022533; Fri, 25 Jan 2013 00:43:04 -0600 Received: from elgon.mountain (/41.212.103.53) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Jan 2013 22:43:03 -0800 Date: Fri, 25 Jan 2013 09:42:59 +0300 From: Dan Carpenter To: Florian Tobias Schandinat Cc: linux-fbdev@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch 2/2] video/kyro: some potential divide by zero bugs Message-ID: <20130125064259.GD4882@elgon.mountain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org These values come from the user in kyrofb_ioctl(). There are a couple potential divide by zero problems and I have added tests for them. There were a couple tests to prevent divide by zero bugs already in the code that I moved next to the assignments. Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/video/kyro/STG4000OverlayDevice.c b/drivers/video/kyro/STG4000OverlayDevice.c index 84b6ea8..d03a1e4 100644 --- a/drivers/video/kyro/STG4000OverlayDevice.c +++ b/drivers/video/kyro/STG4000OverlayDevice.c @@ -365,15 +365,18 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg, ulSrcBottom = srcDest.ulSrcY2; ulSrc = ulSrcBottom - ulSrcTop; - ulDest = srcDest.lDstY2 - srcDest.lDstY1; /* on-screen overlay */ - if (ulSrc <= 1) return -EINVAL; + ulDest = srcDest.lDstY2 - srcDest.lDstY1; /* on-screen overlay */ + if (ulDest == -1) + return -EINVAL; /* First work out the position we are to display as offset from the * source of the buffer */ ulFxScale = (ulDest << 11) / ulSrc; /* fixed point scale factor */ + if (ulFxScale == 0) + return -EINVAL; ulFxOffset = (srcDest.lDstY2 - srcDest.ulDstY2) << 11; ulSrcBottom = ulSrcBottom - (ulFxOffset / ulFxScale); @@ -430,6 +433,8 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg, */ ulSrc = srcDest.ulSrcX2 - srcDest.ulSrcX1; ulDest = srcDest.lDstX2 - srcDest.lDstX1; + if (ulDest == 0) + return -EINVAL; if (srcDest.ulDstX1 > 2) { ulLeft = srcDest.ulDstX1 + 2; @@ -438,14 +443,14 @@ int SetOverlayViewPort(volatile STG4000REG __iomem *pSTGReg, ulLeft = srcDest.ulDstX1; ulRight = srcDest.ulDstX2 + 1; } + if (ulRight - ulLeft + 2 == 0) + return -EINVAL; + /* first work out the position we are to display as offset from the source of the buffer */ bResult = 1; do { - if (ulDest == 0) - return -EINVAL; - /* source pixels per dest pixel <<11 */ ulFxScale = ((ulSrc - 1) << 11) / (ulDest);