From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113586 invoked by alias); 26 Feb 2020 04:56:59 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 113574 invoked by uid 89); 26 Feb 2020 04:56:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=hurry, HX-HELO:sk:mail-pl X-HELO: mail-pl1-f175.google.com Received: from mail-pl1-f175.google.com (HELO mail-pl1-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Feb 2020 04:56:57 +0000 Received: by mail-pl1-f175.google.com with SMTP id q4so789108pls.4 for ; Tue, 25 Feb 2020 20:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Bs08D+i55obTTww/PrCibQGlVXS4ex/dnUB8YUwiN5E=; b=HSv3PrbrCod4kfybKu5FkQZ2c82siDaiA4DOaF06FOvfaH/FCvPuRGaoOLZ90iM82v ErLrosWBJRuvLUkwE+aCxNEoKBlA7qhvNRItr/Jj+gtGhhkRaAuzUWJx1LYhUFTFhCfQ yuQ7GiP0whjMu9LHKFqO8d2kUOB1QfH3HboskeFzDL+tqR1imlsnE3XP/eX/NTLZLJ5O GRgEIfygGDm/zNHhf2c7oGh681r9vxhlRPjGl8bwHSVE/ZvB3QNbAEQAVhdlNpq/gm/7 pBXifhAM7mUcqYom34eF7SFxhej4LQ3zx2e/IGuQCt4wCi7vsuvvYvkxxLZj0G42G3KS Gykw== Return-Path: Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:a0d2:f6ab:12f5:1b30]) by smtp.gmail.com with ESMTPSA id p21sm799154pfn.103.2020.02.25.20.56.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 20:56:54 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id D22568085E; Wed, 26 Feb 2020 15:26:50 +1030 (ACDT) Date: Wed, 26 Feb 2020 04:56:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: Re: vms buffer overflows and large memory allocation Message-ID: <20200226045650.GG5750@bubble.grove.modra.org> References: <20200224020650.GD5570@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200224020650.GD5570@bubble.grove.modra.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00548.txt.bz2 git commit c893ce360a changed buffer management, in the process introducing a bug on an error return path. Obviously committed in too much of a hurry. * vms-lib.c (vms_lib_read_index): Release correct buffer. diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c index 87f865864c..29e213f8c3 100644 --- a/bfd/vms-lib.c +++ b/bfd/vms-lib.c @@ -416,6 +416,7 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel) unsigned int vbn; ufile_ptr filesize; size_t amt; + struct carsym *csbuf; struct carsym_mem csm; /* Read index desription. */ @@ -447,7 +448,7 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel) csm.max = csm.limit; if (_bfd_mul_overflow (csm.max, sizeof (struct carsym), &amt)) return NULL; - csm.idx = bfd_alloc (abfd, amt); + csm.idx = csbuf = bfd_alloc (abfd, amt); if (csm.idx == NULL) return NULL; @@ -455,12 +456,12 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel) vbn = bfd_getl32 (idd.vbn); if (vbn != 0 && !vms_traverse_index (abfd, vbn, &csm)) { - if (csm.realloced && csm.idx != NULL) + if (csm.realloced) free (csm.idx); /* Note: in case of error, we can free what was allocated on the BFD's objalloc. */ - bfd_release (abfd, csm.idx); + bfd_release (abfd, csbuf); return NULL; } @@ -468,7 +469,6 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel) { /* There are more entries than the first estimate. Allocate on the BFD's objalloc. */ - struct carsym *csbuf; csbuf = bfd_alloc (abfd, csm.nbr * sizeof (struct carsym)); if (csbuf == NULL) return NULL; -- Alan Modra Australia Development Lab, IBM