From patchwork Mon Aug 24 19:54:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 7066641 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6210E9F402 for ; Mon, 24 Aug 2015 19:54:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98965204AF for ; Mon, 24 Aug 2015 19:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C97620778 for ; Mon, 24 Aug 2015 19:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754156AbbHXTye (ORCPT ); Mon, 24 Aug 2015 15:54:34 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:39690 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753993AbbHXTye (ORCPT ); Mon, 24 Aug 2015 15:54:34 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7OJsTZ4006399 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Aug 2015 19:54:30 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t7OJsSRf001603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 24 Aug 2015 19:54:29 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t7OJsSv6020289; Mon, 24 Aug 2015 19:54:28 GMT Received: from mwanda (/154.0.139.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Aug 2015 12:54:28 -0700 Date: Mon, 24 Aug 2015 22:54:21 +0300 From: Dan Carpenter To: Jean-Christophe Plagniol-Villard Cc: Tomi Valkeinen , Andy Shevchenko , linux-fbdev@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch v2] fbdev: fix snprintf() limit in show_bl_curve() Message-ID: <20150824195421.GA12634@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1440148923.23472.15.camel@linux.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The limit should be "PAGE_SIZE - len" instead of PAGE_SIZE. Also let's use scnprintf() because snprintf() returns the number of bytes which would have been printed if there were space and scnprintf() returns the number of bytes actually printed. I don't think we are ever going to actually hit this limit in real life. 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/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c index 60c3f0a..15755ce 100644 --- a/drivers/video/fbdev/core/fbsysfs.c +++ b/drivers/video/fbdev/core/fbsysfs.c @@ -485,7 +485,7 @@ static ssize_t show_bl_curve(struct device *device, mutex_lock(&fb_info->bl_curve_mutex); for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8) - len += snprintf(&buf[len], PAGE_SIZE, "%8ph\n", + len += scnprintf(&buf[len], PAGE_SIZE - len, "%8ph\n", fb_info->bl_curve + i); mutex_unlock(&fb_info->bl_curve_mutex);