From owner-svn-src-all@FreeBSD.ORG Mon Feb 23 01:24:11 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EB4D4D1F; Mon, 23 Feb 2015 01:24:11 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 D5F4C265; Mon, 23 Feb 2015 01:24:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1N1OBFs083623; Mon, 23 Feb 2015 01:24:11 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1N1OBW1083622; Mon, 23 Feb 2015 01:24:11 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201502230124.t1N1OBW1083622@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Mon, 23 Feb 2015 01:24:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r279196 - stable/10/sys/kern X-SVN-Group: stable-10 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.18-1 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: Mon, 23 Feb 2015 01:24:12 -0000 Author: markj Date: Mon Feb 23 01:24:10 2015 New Revision: 279196 URL: https://svnweb.freebsd.org/changeset/base/279196 Log: MFC r278983: Free the zlib stream once the CTF section is decompressed. MFC r278984: Remove unnecessary checks for a NULL return value from malloc. MFC r279089: Let vn_rdwr() check for short reads. Modified: stable/10/sys/kern/kern_ctf.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_ctf.c ============================================================================== --- stable/10/sys/kern/kern_ctf.c Mon Feb 23 01:17:45 2015 (r279195) +++ stable/10/sys/kern/kern_ctf.c Mon Feb 23 01:24:10 2015 (r279196) @@ -68,7 +68,6 @@ link_elf_ctf_get(linker_file_t lf, linke int flags; int i; int nbytes; - ssize_t resid; size_t sz; struct nameidata nd; struct thread *td = curthread; @@ -121,14 +120,11 @@ link_elf_ctf_get(linker_file_t lf, linke NDFREE(&nd, NDF_ONLY_PNBUF); /* Allocate memory for the FLF header. */ - if ((hdr = malloc(sizeof(*hdr), M_LINKER, M_WAITOK)) == NULL) { - error = ENOMEM; - goto out; - } + hdr = malloc(sizeof(*hdr), M_LINKER, M_WAITOK); /* Read the ELF header. */ if ((error = vn_rdwr(UIO_READ, nd.ni_vp, hdr, sizeof(*hdr), - 0, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, &resid, + 0, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, NULL, td)) != 0) goto out; @@ -146,15 +142,12 @@ link_elf_ctf_get(linker_file_t lf, linke } /* Allocate memory for all the section headers */ - if ((shdr = malloc(nbytes, M_LINKER, M_WAITOK)) == NULL) { - error = ENOMEM; - goto out; - } + shdr = malloc(nbytes, M_LINKER, M_WAITOK); /* Read all the section headers */ if ((error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)shdr, nbytes, hdr->e_shoff, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, - &resid, td)) != 0) + NULL, td)) != 0) goto out; /* @@ -171,17 +164,12 @@ link_elf_ctf_get(linker_file_t lf, linke } /* Allocate memory to buffer the section header strings. */ - if ((shstrtab = malloc(shdr[hdr->e_shstrndx].sh_size, M_LINKER, - M_WAITOK)) == NULL) { - error = ENOMEM; - goto out; - } + shstrtab = malloc(shdr[hdr->e_shstrndx].sh_size, M_LINKER, M_WAITOK); /* Read the section header strings. */ if ((error = vn_rdwr(UIO_READ, nd.ni_vp, shstrtab, shdr[hdr->e_shstrndx].sh_size, shdr[hdr->e_shstrndx].sh_offset, - UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, &resid, - td)) != 0) + UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED, NULL, td)) != 0) goto out; /* Search for the section containing the CTF data. */ @@ -200,7 +188,7 @@ link_elf_ctf_get(linker_file_t lf, linke /* Read the CTF header. */ if ((error = vn_rdwr(UIO_READ, nd.ni_vp, ctf_hdr, sizeof(ctf_hdr), shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, - NOCRED, &resid, td)) != 0) + NOCRED, NULL, td)) != 0) goto out; /* Check the CTF magic number. (XXX check for big endian!) */ @@ -238,10 +226,7 @@ link_elf_ctf_get(linker_file_t lf, linke * Allocate memory for the compressed CTF data, including * the header (which isn't compressed). */ - if ((raw = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK)) == NULL) { - error = ENOMEM; - goto out; - } + raw = malloc(shdr[i].sh_size, M_LINKER, M_WAITOK); } else { /* * The CTF data is not compressed, so the ELF section @@ -254,10 +239,7 @@ link_elf_ctf_get(linker_file_t lf, linke * Allocate memory to buffer the CTF data in it's decompressed * form. */ - if ((ctftab = malloc(sz, M_LINKER, M_WAITOK)) == NULL) { - error = ENOMEM; - goto out; - } + ctftab = malloc(sz, M_LINKER, M_WAITOK); /* * Read the CTF data into the raw buffer if compressed, or @@ -265,7 +247,7 @@ link_elf_ctf_get(linker_file_t lf, linke */ if ((error = vn_rdwr(UIO_READ, nd.ni_vp, raw == NULL ? ctftab : raw, shdr[i].sh_size, shdr[i].sh_offset, UIO_SYSSPACE, IO_NODELOCKED, - td->td_ucred, NOCRED, &resid, td)) != 0) + td->td_ucred, NOCRED, NULL, td)) != 0) goto out; /* Check if decompression is required. */ @@ -293,7 +275,9 @@ link_elf_ctf_get(linker_file_t lf, linke zs.next_in = ((uint8_t *) raw) + sizeof(ctf_hdr); zs.avail_out = sz - sizeof(ctf_hdr); zs.next_out = ((uint8_t *) ctftab) + sizeof(ctf_hdr); - if ((ret = inflate(&zs, Z_FINISH)) != Z_STREAM_END) { + ret = inflate(&zs, Z_FINISH); + inflateEnd(&zs); + if (ret != Z_STREAM_END) { printf("%s(%d): zlib inflate returned %d\n", __func__, __LINE__, ret); error = EIO; goto out;