From owner-freebsd-audit Mon Apr 2 7:57:15 2001 Delivered-To: freebsd-audit@freebsd.org Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by hub.freebsd.org (Postfix) with ESMTP id 0BB5337B722 for ; Mon, 2 Apr 2001 07:57:11 -0700 (PDT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (robert@fledge.pr.watson.org [192.0.2.3]) by fledge.watson.org (8.11.1/8.11.1) with SMTP id f32EvBh90055 for ; Mon, 2 Apr 2001 10:57:11 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Mon, 2 Apr 2001 10:57:11 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: freebsd-audit@FreeBSD.org Subject: [ANNOUNCEMENT] OpenSSL 0.9.6a Beta 3 released (fwd) Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I notice that one of the release notes in the 0.9.6a OpenSSL release has to do with avoiding the use of environmental variables when running as root. Could someone take a look at our OpenSSL code and see if we have problems relating to this, also, it might be worth checking that the OpenSSL folk use issetguid() rather than get*id(). Robert N M Watson FreeBSD Core Team, TrustedBSD Project robert@fledge.watson.org NAI Labs, Safeport Network Services ---------- Forwarded message ---------- Date: Fri, 30 Mar 2001 22:45:06 +0200 From: Richard Levitte Reply-To: openssl-dev@openssl.org To: openssl-announce@openssl.org, openssl-users@openssl.org, openssl-dev@openssl.org, coderpunks@toad.com, cypherpunks@openpgp.net, cryptography@c2.net, VMS-SSH@ALPHA.SGGW.WAW.PL, INFO-VAX@MVB.SAIC.COM, VMS-WEB-DAEMON@KJSL.COM, info-wasd@vsm.com.au Subject: [ANNOUNCEMENT] OpenSSL 0.9.6a Beta 3 released The third beta release of OpenSSL 0.9.6a is now available from the OpenSSL FTP site . OpenSSL 0.9.6a is a bug-fix release of version 0.9.6, and currently contains 52 documented changes. Among others, this release should build on all Windows platforms, which 0.9.6 failed to do. Just as for version 0.9.6, this one comes in two variants, one containing the now well-known ENGINE code and one that doesn't. The tar files are: openssl-0.9.6a-beta3.tar.gz openssl-engine-0.9.6a-beta3.tar.gz The news section for 0.9.6a gives the following: o Security fix: change behavior of OpenSSL to avoid using environment variables when running as root. o Security fix: check the result of RSA-CRT to reduce the possibility of deducing the private key from an incorrectly calculated signature. o Security fix: prevent Bleichenbacher's DSA attack. o Security fix: Zero the premaster secret after deriving the master secret in DH ciphersuites. o Reimplement SSL_peek(), which had various problems. o Compatibility fix: the function des_encrypt() renamed to des_encrypt1() to avoid clashes with some Unixen libc. o Bug fixes for Win32, HP/UX and Irix. o Bug fixes in BIGNUM, SSL, PKCS#7, PKCS#12, X.509, CONF and memory checking routines. o Bug fixes for RSA operations in threaded enviroments. o Bug fixes in misc. openssl applications. o Remove a few potential memory leaks. o Add tighter checks of BIGNUM routines. o Shared library support has been reworked for generality. o More documentation. o New function BN_rand_range(). o Add "-rand" option to openssl s_client and s_server. The next (hopefully real) release is scheduled for Tuesday 2001-04-03. To make sure that it will work correctly, please test this version (especially on less common platforms), and report any problems to . -- Richard Levitte levitte@openssl.org OpenSSL Project http://www.openssl.org/~levitte/ Software Engineer, Celo Communications: http://www.celocom.com/ ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List openssl-dev@openssl.org Automated List Manager majordomo@openssl.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Apr 3 3:58:37 2001 Delivered-To: freebsd-audit@freebsd.org Received: from ida.interface-business.de (ida.interface-business.de [193.101.57.9]) by hub.freebsd.org (Postfix) with ESMTP id 0F48537B71A for ; Tue, 3 Apr 2001 03:58:32 -0700 (PDT) (envelope-from j@ida.interface-business.de) Received: (from j@localhost) by ida.interface-business.de id f33AwPK77332 for audit@freebsd.org; Tue, 3 Apr 2001 12:58:25 +0200 (MET DST) Date: Tue, 3 Apr 2001 12:58:25 +0200 From: J Wunsch To: audit@freebsd.org Subject: security nit in lpr/common/common.c? Message-ID: <20010403125825.C75920@ida.interface-business.de> Reply-To: Joerg Wunsch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Phone: +49-351-31809-14 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Organization: interface systems GmbH, Dresden Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi all, the following doesn't seem to be quite right to me: while ((d = readdir(dirp)) != NULL) { if (d->d_name[0] != 'c' || d->d_name[1] != 'f') continue; /* daemon control files only */ seteuid(euid); if (stat(d->d_name, &stbuf) < 0) continue; /* Doesn't exist */ seteuid(uid); Shouldn't this be while ((d = readdir(dirp)) != NULL) { int i; if (d->d_name[0] != 'c' || d->d_name[1] != 'f') continue; /* daemon control files only */ seteuid(euid); i = stat(d->d_name, &stbuf); seteuid(uid); if (i < 0) continue; /* Doesn't exist */ instead? Judging from some ktrace output it's not really a security problem since the switch is from/to UID 0, but just in case... -- J"org Wunsch Unix support engineer joerg_wunsch@interface-systems.de http://www.interface-systems.de/~j To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Apr 3 7:41:49 2001 Delivered-To: freebsd-audit@freebsd.org Received: from dragon.nuxi.com (trang.nuxi.com [209.152.133.57]) by hub.freebsd.org (Postfix) with ESMTP id 09DFF37B719; Tue, 3 Apr 2001 07:41:43 -0700 (PDT) (envelope-from obrien@NUXI.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.11.3/8.11.1) id f33Efgv23850; Tue, 3 Apr 2001 07:41:42 -0700 (PDT) (envelope-from obrien) Date: Tue, 3 Apr 2001 07:41:42 -0700 From: "David O'Brien" To: audit@freebsd.org, security-officer@freebsd.org Subject: Re: cvs commit: src/contrib/tcpdump - Imported sources Message-ID: <20010403074142.B23625@dragon.nuxi.com> Reply-To: obrien@freebsd.org References: <200104030745.f337jsS07491@freefall.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200104030745.f337jsS07491@freefall.freebsd.org>; from fenner@FreeBSD.org on Tue, Apr 03, 2001 at 12:45:54AM -0700 X-Operating-System: FreeBSD 5.0-CURRENT Organization: The NUXI BSD group X-Pgp-Rsa-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Rsa-Keyid: 1024/34F9F9D5 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, Apr 03, 2001 at 12:45:54AM -0700, Bill Fenner wrote: > fenner 2001/04/03 00:45:54 PDT > Log Message: > Virgin import of tcpdump.org tcpdump v3.6.2 > Vendor Tag: TCPDUMP_ORG > > 39 conflicts created by this import. Committers should keep their hands off of TCPDUMP from now on. All commits to it should be filtered thru Bill Fenner (or myself (as a src/contrib kind-of-guy) if Bill is busy). The great number of conflicts (many of them could have easily been handled on the vendor branch) greatly delayed this update. Security Team and -audit, please take heed. -- -- David (obrien@FreeBSD.org) Disclaimer: Not speaking for FreeBSD, just expressing my own opinion. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Tue Apr 3 8:57:41 2001 Delivered-To: freebsd-audit@freebsd.org Received: from mail.rpi.edu (mail.rpi.edu [128.113.22.40]) by hub.freebsd.org (Postfix) with ESMTP id CA3D437B722 for ; Tue, 3 Apr 2001 08:57:38 -0700 (PDT) (envelope-from drosih@rpi.edu) Received: from [128.113.24.47] (gilead.acs.rpi.edu [128.113.24.47]) by mail.rpi.edu (8.9.3/8.9.3) with ESMTP id LAA37866; Tue, 3 Apr 2001 11:57:29 -0400 Mime-Version: 1.0 X-Sender: drosih@mail.rpi.edu Message-Id: In-Reply-To: <20010403125825.C75920@ida.interface-business.de> References: <20010403125825.C75920@ida.interface-business.de> Date: Tue, 3 Apr 2001 11:57:28 -0400 To: Joerg Wunsch , audit@FreeBSD.ORG From: Garance A Drosihn Subject: Re: security nit in lpr/common/common.c? Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG At 12:58 PM +0200 4/3/01, J Wunsch wrote: >Shouldn't this be > > while ((d = readdir(dirp)) != NULL) { > int i; > > if (d->d_name[0] != 'c' || d->d_name[1] != 'f') > continue; /* daemon control files only */ > seteuid(euid); > i = stat(d->d_name, &stbuf); > seteuid(uid); > if (i < 0) > continue; /* Doesn't exist */ > >instead? Yes, something like that would be more strictly correct. I'll change it. -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Wed Apr 4 8:27: 7 2001 Delivered-To: freebsd-audit@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id 7B9E837B76D; Wed, 4 Apr 2001 08:26:45 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id BAA11353; Thu, 5 Apr 2001 01:26:31 +1000 Date: Thu, 5 Apr 2001 01:25:16 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Peter Pentchev Cc: freebsd-qa@FreeBSD.ORG, freebsd-audit@FreeBSD.ORG Subject: Re: [Fwd: Re: bin/25243: ftp crashes in remotemodtime ().] In-Reply-To: <20010330153503.B33524@ringworld.oblivion.bg> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, 30 Mar 2001, Peter Pentchev wrote: > Uhm. I think this should be fixed in time for 4.3 :) I committed a fix for -current in rev.1.14 of ftp/util.c (since I helped break it :-(). Fixing it in 4.3 doesn't seem as urgent as when I started to fix it. There is only a problem for the broken servers that send the time in a form not understood by ftp. Prior to rev.1.10, ftp converted time strings that it didn't understand into garbage timestamps. > ----- Forwarded message from Peter Pentchev ----- > > Date: Tue, 20 Feb 2001 23:00:04 -0800 (PST) > To: freebsd-bugs@FreeBSD.org > Cc: > From: Peter Pentchev > Subject: Re: bin/25243: ftp crashes in remotemodtime (). > Reply-To: Peter Pentchev > > The following reply was made to PR bin/25243; it has been noted by GNATS. > > From: Peter Pentchev > To: fumis@bigfoot.com > Cc: freebsd-gnats-submit@FreeBSD.org > Subject: Re: bin/25243: ftp crashes in remotemodtime (). > Date: Wed, 21 Feb 2001 08:55:45 +0200 > > On Tue, Feb 20, 2001 at 09:35:01PM -0800, fumis@bigfoot.com wrote: > > > > >Number: 25243 > > >Category: bin > > >Synopsis: ftp crashes in remotemodtime (). > > >Originator: SHIMIZU Fumiyuki > > >Release: 4.2-STABLE > > >Organization: > > >Environment: > > FreeBSD ***snip*** 4.2-STABLE FreeBSD 4.2-STABLE #1: Tue Feb 20 14:01:10 JST 2001 ***snip*** > > >Description: > > /usr/bin/ftp crashes after getting a file. > > > > ftp> get foobar > > local: foobar remote: foobar > > 227 Entering Passive Mode (***snip***) > > 150 Opening data connection for foobar (696075740 bytes). > > 100% |**************************************************| 663 MB 00:00 ETA > > 226 Transfer complete. > > 696075740 bytes received in 11999.42 seconds (56.65 KB/s) > > Segmentation fault - core dumped > > > > >How-To-Repeat: > > Connect to ftpd which answers with less than 14 or more than 15 characters against `MDTM' request, and get some files. > > > > >Fix: > > Braces required just after `if (fmt != NULL)' in remotemodtime (). > > /usr/src/usr.bin/ftp/util.c, line 533 > > And the patch itself (trivial, yet needed indeed).. > > G'luck, > Peter > > -- > "yields falsehood, when appended to its quotation." yields falsehood, when appended to its quotation. > > Index: src/usr.bin/ftp/util.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/ftp/util.c,v > retrieving revision 1.13 > diff -u -r1.13 util.c > --- src/usr.bin/ftp/util.c 2000/05/22 17:18:38 1.13 > +++ src/usr.bin/ftp/util.c 2001/02/21 06:52:52 > @@ -529,7 +529,7 @@ > y2kbug = 1; > } else if (len == 14) > fmt = "%04d%02d%02d%02d%02d%02d"; > - if (fmt != NULL) > + if (fmt != NULL) { > memset(&timebuf, 0, sizeof(timebuf)); > if (sscanf(mtbuf, fmt, &year, &month, > &timebuf.tm_mday, &timebuf.tm_hour, > @@ -542,6 +542,7 @@ > timebuf.tm_year = year - 1900; > rtime = mktime(&timebuf); > } > + } > } > if (rtime == -1 && (noisy || debug != 0)) > printf("Can't convert %s to a time.\n", mtbuf); > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-bugs" in the body of the message > > > ----- End forwarded message ----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message From owner-freebsd-audit Fri Apr 6 5:35: 4 2001 Delivered-To: freebsd-audit@freebsd.org Received: from ipcard.iptcom.net (ipcard.iptcom.net [212.9.224.5]) by hub.freebsd.org (Postfix) with ESMTP id 425D237B423; Fri, 6 Apr 2001 05:34:37 -0700 (PDT) (envelope-from sobomax@FreeBSD.org) Received: from vic.sabbo.net (dialup16-27.iptelecom.net.ua [212.9.229.219]) by ipcard.iptcom.net (8.9.3/8.9.3) with ESMTP id PAA09417; Fri, 6 Apr 2001 15:34:30 +0300 (EEST) (envelope-from sobomax@FreeBSD.org) Received: from FreeBSD.org (big_brother.vega.com [192.168.1.1]) by vic.sabbo.net (8.11.3/8.11.2) with ESMTP id f36CXxt72936; Fri, 6 Apr 2001 15:33:59 +0300 (EEST) (envelope-from sobomax@FreeBSD.org) Message-ID: <3ACDB7B6.74973132@FreeBSD.org> Date: Fri, 06 Apr 2001 15:33:58 +0300 From: Maxim Sobolev Organization: Vega International Capital X-Mailer: Mozilla 4.76 [en] (WinNT; U) X-Accept-Language: uk,ru,en MIME-Version: 1.0 To: hackers@FreeBSD.org, audit@FreeBSD.org Subject: Automatic fontsize definition in vidcontrol(8) [patch] Content-Type: multipart/mixed; boundary="------------BF05896831049C5323D4B762" Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------BF05896831049C5323D4B762 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit Hi, I found it very frustrating that each time I need to change console font (my native language has 3 different encodings, so I need to do it regularly) I have to specify not only the font name, but fontsize as well. I do not see any reasons why vidcontrol(8) can't guess correct value from the fontfile itself, especially considering that there is 1-to-1 mapping between size of the fontdata and font dimensions. With this message I'm attaching small patch that adds this functionality to the utility. In addition, this patch makes vidcontrol(8) more robust, fixing the following issues: o previously vidcontrol could be crashed easily by specifying a valid uuencoded file with undecoded size greater than the size of the buffer allocated for that particular fontsize (the same applies for the screenmap). Now decoding routine will discard any data that exceed the size of the buffer; o previously it was quite easy to trash fonts on your console by erroneously specifying an arbitrary binary file (or even a directory) instead of a fontfile. Now the utility will refuse to load a binary file, unless its size is equal to one of 3 possible valid sizes, thus greatly reducing a possibility of an error. Please somebody review attached patches. Thanks! -Maxim --------------BF05896831049C5323D4B762 Content-Type: text/plain; charset=koi8-r; name="vidcontrol.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vidcontrol.diff" Index: decode.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/vidcontrol/decode.c,v retrieving revision 1.8 diff -d -u -r1.8 decode.c --- decode.c 1999/08/28 01:20:29 1.8 +++ decode.c 2001/04/06 12:08:43 @@ -35,10 +35,11 @@ #include #include "decode.h" -int decode(FILE *fd, char *buffer) +int decode(FILE *fd, char *buffer, int len) { - int n, pos = 0; - char *p; + int n, pos = 0, tpos; + char *bp, *p; + char tbuffer[3]; char temp[128]; #define DEC(c) (((c) - ' ') & 0x3f) @@ -48,31 +49,49 @@ return(0); } while (strncmp(temp, "begin ", 6)); sscanf(temp, "begin %o %s", &n, temp); + bp = buffer; for (;;) { if (!fgets(p = temp, sizeof(temp), fd)) return(0); if ((n = DEC(*p)) <= 0) break; - for (++p; n > 0; p += 4, n -= 3) + for (++p; n > 0; p += 4, n -= 3) { + tpos = 0; if (n >= 3) { - buffer[pos++] = DEC(p[0])<<2 | DEC(p[1])>>4; - buffer[pos++] = DEC(p[1])<<4 | DEC(p[2])>>2; - buffer[pos++] = DEC(p[2])<<6 | DEC(p[3]); + tbuffer[tpos++] = DEC(p[0])<<2 | DEC(p[1])>>4; + tbuffer[tpos++] = DEC(p[1])<<4 | DEC(p[2])>>2; + tbuffer[tpos++] = DEC(p[2])<<6 | DEC(p[3]); } else { if (n >= 1) { - buffer[pos++] = + tbuffer[tpos++] = DEC(p[0])<<2 | DEC(p[1])>>4; } if (n >= 2) { - buffer[pos++] = + tbuffer[tpos++] = DEC(p[1])<<4 | DEC(p[2])>>2; } if (n >= 3) { - buffer[pos++] = + tbuffer[tpos++] = DEC(p[2])<<6 | DEC(p[3]); } } + if (tpos == 0) + continue; + if (tpos + pos > len) { + tpos = len - pos; + /* + * Arrange return value > len to indicate + * overflow. + */ + pos++; + } + bcopy(tbuffer, bp, tpos); + pos += tpos; + bp += tpos; + if (pos > len) + return(pos); + } } if (!fgets(temp, sizeof(temp), fd) || strcmp(temp, "end\n")) return(0); Index: decode.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/vidcontrol/decode.h,v retrieving revision 1.1 diff -d -u -r1.1 decode.h --- decode.h 1997/03/07 01:34:44 1.1 +++ decode.h 2001/04/06 12:08:43 @@ -1 +1,3 @@ -int decode(FILE *fd, char *buffer); +/* $FreeBSD$ */ + +int decode(FILE *fd, char *buffer, int len); Index: vidcontrol.1 =================================================================== RCS file: /home/ncvs/src/usr.sbin/vidcontrol/vidcontrol.1,v retrieving revision 1.30 diff -d -u -r1.30 vidcontrol.1 --- vidcontrol.1 2001/03/28 02:32:10 1.30 +++ vidcontrol.1 2001/04/06 12:08:43 @@ -24,7 +24,7 @@ .Op Fl b Ar color .Op Fl c Ar appearance .Op Fl d -.Op Fl f Ar size Ar file +.Op Fl f Oo Ar size Oc Ar \ file .Op Fl g Ar geometry .Op Fl i Cm adapter | mode .Op Fl l Ar screen_map @@ -142,7 +142,7 @@ Used together with the .Xr moused 8 daemon for text mode cut & paste functionality. -.It Fl f Ar size Ar file +.It Fl f [ Ar size ] Ar file Load font .Ar file for @@ -157,6 +157,11 @@ .Xr vidfont 1 command to load the font of your choice. .Pp +.Ar Size +may be omitted, in this case +.Nm +will try to guess it from the size of font file. +.Pp Note that older video cards, such as MDA and CGA, do not support software font. See also @@ -295,6 +300,11 @@ .Pa iso-8x16 : .Pp .Dl vidcontrol -f 8x16 iso-8x16 +.Pp +Furthermore, you can also omit font size +.Dq 8x16 : +.Pp +.Dl vidcontrol -f iso-8x16 .Pp Likewise, you can also abbreviate the screen output map file name for the Index: vidcontrol.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/vidcontrol/vidcontrol.c,v retrieving revision 1.34 diff -d -u -r1.34 vidcontrol.c --- vidcontrol.c 2001/01/25 16:53:22 1.34 +++ vidcontrol.c 2001/04/06 12:08:44 @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include "path.h" #include "decode.h" @@ -74,12 +76,13 @@ } char * -nextarg(int ac, char **av, int *indp, int oc) +nextarg(int ac, char **av, int *indp, int oc, int strict) { if (*indp < ac) return(av[(*indp)++]); - errx(1, "option requires two arguments -- %c", oc); - return(""); + if (strict != 0) + errx(1, "option requires two arguments -- %c", oc); + return(NULL); } char * @@ -129,7 +132,7 @@ return; } size = sizeof(scrnmap); - if (decode(fd, (char *)&scrnmap) != size) { + if (decode(fd, (char *)&scrnmap, size) != size) { rewind(fd); if (fread(&scrnmap, 1, size, fd) != size) { warnx("bad screenmap file"); @@ -176,16 +179,38 @@ } +int +fsize(FILE *file) +{ + struct stat sb; + + if (fstat(fileno(file), &sb) == 0) + return sb.st_size; + else + return -1; +} + +#define DATASIZE(x) ((x).w * (x).h * 256 / 8) + void load_font(char *type, char *filename) { - FILE *fd = 0; - int i, size; - unsigned long io; + FILE *fd = NULL; + int h, i, size, w; + unsigned long io = 0; /* silence stupid gcc(1) in the Wall mode */ char *name, *fontmap; char *prefix[] = {"", "", FONT_PATH, FONT_PATH, NULL}; char *postfix[] = {"", ".fnt", "", ".fnt"}; + struct sizeinfo { + int w; + int h; + unsigned long io; + } sizes[] = {{8, 16, PIO_FONT8x16}, + {8, 14, PIO_FONT8x14}, + {8, 8, PIO_FONT8x8}, + {0, 0, 0}}; + for (i=0; prefix[i]; i++) { name = mkfullname(prefix[i], filename, postfix[i]); fd = fopen(name, "r"); @@ -193,31 +218,57 @@ break; } if (fd == NULL) { - warn("font file not found"); + warnx("%s: font file not found", filename); return; - } - if (!strcmp(type, "8x8")) { - size = 8*256; - io = PIO_FONT8x8; } - else if (!strcmp(type, "8x14")) { - size = 14*256; - io = PIO_FONT8x14; - } - else if (!strcmp(type, "8x16")) { - size = 16*256; - io = PIO_FONT8x16; - } - else { - warn("bad font size specification"); - fclose(fd); - return; + if (type != NULL) { + size = 0; + if (sscanf(type, "%dx%d", &w, &h) == 2) + for (i = 0; sizes[i].w != 0; i++) + if (sizes[i].w == w && sizes[i].h == h) { + size = DATASIZE(sizes[i]); + io = sizes[i].io; + } + + if (size == 0) { + warnx("%s: bad font size specification", type); + fclose(fd); + return; + } + } else { + /* Apply heuristics */ + int j; + int dsize[2]; + + size = DATASIZE(sizes[0]); + fontmap = (char*) malloc(size); + dsize[0] = decode(fd, fontmap, size); + dsize[1] = fsize(fd); + free(fontmap); + + size = 0; + for (j = 0; j < 2; j++) + for (i = 0; sizes[i].w != 0; i++) + if (DATASIZE(sizes[i]) == dsize[j]) { + size = dsize[j]; + io = sizes[i].io; + j = 2; /* XXX */ + break; + } + + if (size == 0) { + warnx("%s: can't guess font size", filename); + fclose(fd); + return; + } + rewind(fd); } + fontmap = (char*) malloc(size); - if (decode(fd, fontmap) != size) { + if (decode(fd, fontmap, size) != size) { rewind(fd); - if (fread(fontmap, 1, size, fd) != size) { - warnx("bad font file"); + if (fsize(fd) != size || fread(fontmap, 1, size, fd) != size) { + warnx("%s: bad font file", filename); fclose(fd); free(fontmap); return; @@ -590,7 +641,8 @@ int main(int argc, char **argv) { - int opt; + char *font, *type; + int opt; info.size = sizeof(info); @@ -608,8 +660,13 @@ print_scrnmap(); break; case 'f': - load_font(optarg, - nextarg(argc, argv, &optind, 'f')); + type = optarg; + font = nextarg(argc, argv, &optind, 'f', 0); + if (font == NULL) { + type = NULL; + font = optarg; + } + load_font(type, font); break; case 'g': if (sscanf(optarg, "%dx%d", &vesa_cols, --------------BF05896831049C5323D4B762-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message