From owner-svn-src-head@freebsd.org Tue Mar 7 19:30:24 2017 Return-Path: Delivered-To: svn-src-head@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 F3B0FD018DB; Tue, 7 Mar 2017 19:30:23 +0000 (UTC) (envelope-from pfg@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 C32E21023; Tue, 7 Mar 2017 19:30:23 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v27JUMBb018084; Tue, 7 Mar 2017 19:30:22 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v27JUMv0018083; Tue, 7 Mar 2017 19:30:22 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201703071930.v27JUMv0018083@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Tue, 7 Mar 2017 19:30:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314877 - head/usr.sbin/lpr/common_source X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Mar 2017 19:30:24 -0000 Author: pfg Date: Tue Mar 7 19:30:22 2017 New Revision: 314877 URL: https://svnweb.freebsd.org/changeset/base/314877 Log: lpr(1): small bounds check with reallocarray(3). While here plug a memory leak upon error and postpose a multiplication until after reallocation has succeded. Hinted partially by: OpenBSD Reviewed by: gad MFC after: 2 weeks Modified: head/usr.sbin/lpr/common_source/common.c Modified: head/usr.sbin/lpr/common_source/common.c ============================================================================== --- head/usr.sbin/lpr/common_source/common.c Tue Mar 7 19:00:50 2017 (r314876) +++ head/usr.sbin/lpr/common_source/common.c Tue Mar 7 19:30:22 2017 (r314877) @@ -167,11 +167,13 @@ getq(const struct printer *pp, struct jo * realloc the maximum size. */ if (++nitems > arraysz) { - arraysz *= 2; - queue = (struct jobqueue **)realloc((char *)queue, - arraysz * sizeof(struct jobqueue *)); - if (queue == NULL) + queue = (struct jobqueue **)reallocarray((char *)queue, + arraysz, 2 * sizeof(struct jobqueue *)); + if (queue == NULL) { + free(q); goto errdone; + } + arraysz *= 2; } queue[nitems-1] = q; }