From owner-svn-src-all@freebsd.org Fri Feb 10 15:02:57 2017 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 D8D26CD8922; Fri, 10 Feb 2017 15:02:57 +0000 (UTC) (envelope-from emaste@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 8C85C1396; Fri, 10 Feb 2017 15:02:57 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1AF2uL7012834; Fri, 10 Feb 2017 15:02:56 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1AF2urd012833; Fri, 10 Feb 2017 15:02:56 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201702101502.v1AF2urd012833@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 10 Feb 2017 15:02:56 +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: r313552 - stable/10/usr.sbin/vidcontrol 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.23 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: Fri, 10 Feb 2017 15:02:58 -0000 Author: emaste Date: Fri Feb 10 15:02:56 2017 New Revision: 313552 URL: https://svnweb.freebsd.org/changeset/base/313552 Log: MFC r308312: vidcontrol: improve error handling in vt(4) font loading PR: 209078 Modified: stable/10/usr.sbin/vidcontrol/vidcontrol.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/vidcontrol/vidcontrol.c ============================================================================== --- stable/10/usr.sbin/vidcontrol/vidcontrol.c Fri Feb 10 14:58:24 2017 (r313551) +++ stable/10/usr.sbin/vidcontrol/vidcontrol.c Fri Feb 10 15:02:56 2017 (r313552) @@ -393,11 +393,15 @@ load_vt4mappingtable(unsigned int nmappi if (nmappings == 0) return (NULL); - t = malloc(sizeof *t * nmappings); + if ((t = malloc(sizeof *t * nmappings)) == NULL) { + warn("malloc"); + return (NULL); + } if (fread(t, sizeof *t * nmappings, 1, f) != 1) { - perror("mappings"); - exit(1); + warn("read mappings"); + free(t); + return (NULL); } for (i = 0; i < nmappings; i++) { @@ -422,7 +426,7 @@ load_default_vt4font(void) } } -static int +static void load_vt4font(FILE *f) { struct vt4font_header fh; @@ -431,13 +435,13 @@ load_vt4font(FILE *f) unsigned int i; if (fread(&fh, sizeof fh, 1, f) != 1) { - perror("file_header"); - return (1); + warn("read file_header"); + return; } if (memcmp(fh.magic, "VFNT0002", 8) != 0) { - fprintf(stderr, "Bad magic\n"); - return (1); + warnx("bad magic in font file\n"); + return; } for (i = 0; i < VFNT_MAPS; i++) @@ -447,21 +451,26 @@ load_vt4font(FILE *f) vfnt.height = fh.height; glyphsize = howmany(vfnt.width, 8) * vfnt.height * vfnt.glyph_count; - vfnt.glyphs = malloc(glyphsize); + if ((vfnt.glyphs = malloc(glyphsize)) == NULL) { + warn("malloc"); + return; + } if (fread(vfnt.glyphs, glyphsize, 1, f) != 1) { - perror("glyphs"); - return (1); + warn("read glyphs"); + free(vfnt.glyphs); + return; } for (i = 0; i < VFNT_MAPS; i++) vfnt.map[i] = load_vt4mappingtable(vfnt.map_count[i], f); - if (ioctl(STDIN_FILENO, PIO_VFONT, &vfnt) == -1) { - perror("PIO_VFONT"); - return (1); - } - return (0); + if (ioctl(STDIN_FILENO, PIO_VFONT, &vfnt) == -1) + warn("PIO_VFONT"); + + for (i = 0; i < VFNT_MAPS; i++) + free(vfnt.map[i]); + free(vfnt.glyphs); } /* @@ -511,8 +520,7 @@ load_font(const char *type, const char * } if (vt4_mode) { - if(load_vt4font(fd)) - warn("failed to load font \"%s\"", filename); + load_vt4font(fd); fclose(fd); return; }