From owner-svn-src-all@freebsd.org Tue Jan 5 10:25:24 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1D978A60F7F; Tue, 5 Jan 2016 10:25:24 +0000 (UTC) (envelope-from uqs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E23DE1B25; Tue, 5 Jan 2016 10:25:23 +0000 (UTC) (envelope-from uqs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u05APMls079492; Tue, 5 Jan 2016 10:25:22 GMT (envelope-from uqs@FreeBSD.org) Received: (from uqs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u05APMcf079491; Tue, 5 Jan 2016 10:25:22 GMT (envelope-from uqs@FreeBSD.org) Message-Id: <201601051025.u05APMcf079491@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: uqs set sender to uqs@FreeBSD.org using -f From: Ulrich Spoerlein Date: Tue, 5 Jan 2016 10:25:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r293193 - head/sys/dev/asmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jan 2016 10:25:24 -0000 Author: uqs Date: Tue Jan 5 10:25:22 2016 New Revision: 293193 URL: https://svnweb.freebsd.org/changeset/base/293193 Log: Fix undefined behavior when using asmc_fan_getstring() It was returning a pointer to stack-allocated memory, so make the allocation at the caller instead. Found by: clang static analyzer Coverity: CID 1245774 Reviewed by: ed, rpaulo Review URL: https://reviews.freebsd.org/D4740 Modified: head/sys/dev/asmc/asmc.c Modified: head/sys/dev/asmc/asmc.c ============================================================================== --- head/sys/dev/asmc/asmc.c Tue Jan 5 09:18:43 2016 (r293192) +++ head/sys/dev/asmc/asmc.c Tue Jan 5 10:25:22 2016 (r293193) @@ -963,14 +963,13 @@ asmc_fan_getvalue(device_t dev, const ch } static char* -asmc_fan_getstring(device_t dev, const char *key, int fan) +asmc_fan_getstring(device_t dev, const char *key, int fan, uint8_t *buf, uint8_t buflen) { - uint8_t buf[16]; char fankey[5]; char* desc; snprintf(fankey, sizeof(fankey), key, fan); - if (asmc_key_read(dev, fankey, buf, sizeof buf) < 0) + if (asmc_key_read(dev, fankey, buf, buflen) < 0) return (NULL); desc = buf+4; @@ -1012,12 +1011,13 @@ asmc_mb_sysctl_fanspeed(SYSCTL_HANDLER_A static int asmc_mb_sysctl_fanid(SYSCTL_HANDLER_ARGS) { + uint8_t buf[16]; device_t dev = (device_t) arg1; int fan = arg2; int error = true; char* desc; - desc = asmc_fan_getstring(dev, ASMC_KEY_FANID, fan); + desc = asmc_fan_getstring(dev, ASMC_KEY_FANID, fan, buf, sizeof(buf)); if (desc != NULL) error = sysctl_handle_string(oidp, desc, 0, req);