From owner-freebsd-bugs@freebsd.org Tue Apr 26 19:05:44 2016 Return-Path: Delivered-To: freebsd-bugs@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 AB78AB1CF36 for ; Tue, 26 Apr 2016 19:05:44 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (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 905681B49 for ; Tue, 26 Apr 2016 19:05:44 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id u3QJ5iab034962 for ; Tue, 26 Apr 2016 19:05:44 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 209078] Minor bugs in vidcontrol Date: Tue, 26 Apr 2016 19:05:44 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: misc X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: cturt@hardenedbsd.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2016 19:05:44 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D209078 Bug ID: 209078 Summary: Minor bugs in vidcontrol Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: misc Assignee: freebsd-bugs@FreeBSD.org Reporter: cturt@hardenedbsd.org There is a memory leak in the `vidcontrol` utility in the `load_vt4font`: usr.sbin/vidcontrol/vidcontrol.c: static int load_vt4font(FILE *f) { struct vt4font_header fh; static vfnt_t vfnt; size_t glyphsize; unsigned int i; if (fread(&fh, sizeof fh, 1, f) !=3D 1) { perror("file_header"); return (1); } if (memcmp(fh.magic, "VFNT0002", 8) !=3D 0) { fprintf(stderr, "Bad magic\n"); return (1); } for (i =3D 0; i < VFNT_MAPS; i++) vfnt.map_count[i] =3D be32toh(fh.map_count[i]); vfnt.glyph_count =3D be32toh(fh.glyph_count); vfnt.width =3D fh.width; vfnt.height =3D fh.height; glyphsize =3D howmany(vfnt.width, 8) * vfnt.height * vfnt.glyph_cou= nt; vfnt.glyphs =3D malloc(glyphsize); if (fread(vfnt.glyphs, glyphsize, 1, f) !=3D 1) { perror("glyphs"); return (1); } for (i =3D 0; i < VFNT_MAPS; i++) vfnt.map[i] =3D load_vt4mappingtable(vfnt.map_count[i], f); if (ioctl(STDIN_FILENO, PIO_VFONT, &vfnt) =3D=3D -1) { perror("PIO_VFONT"); return (1); } return (0); } After the `vfnt.glyphs` buffer has been allocated with `malloc`, the functi= on can return without freeing the buffer if `fread` or `ioctl` fail. This is only a minor bug, since the process exits almost immediately after calling this function anyway, but I would like to `free` the buffer as a ma= tter of code correctness. This function also doesn't check the return result of `malloc`, which could lead to writing to `NULL` if the allocation fails. My proposal is to add the following lines to this function: vfnt.glyphs =3D malloc(glyphsize); + if (vfnt.glyphs =3D=3D NULL) { + perror("malloc"); + return (1); + } if (fread(vfnt.glyphs, glyphsize, 1, f) !=3D 1) { perror("glyphs"); + free(vfnt.glyphs); return (1); } for (i =3D 0; i < VFNT_MAPS; i++) vfnt.map[i] =3D load_vt4mappingtable(vfnt.map_count[i], f); if (ioctl(STDIN_FILENO, PIO_VFONT, &vfnt) =3D=3D -1) { perror("PIO_VFONT"); + free(vfnt.glyphs); return (1); } --=20 You are receiving this mail because: You are the assignee for the bug.=