From owner-freebsd-bugs Wed Feb 23 22:40:12 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id BB24537BFB3 for ; Wed, 23 Feb 2000 22:40:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id WAA69822; Wed, 23 Feb 2000 22:40:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4A15337BAFF for ; Wed, 23 Feb 2000 22:37:19 -0800 (PST) (envelope-from nobody@FreeBSD.org) Received: (from nobody@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id WAA69495; Wed, 23 Feb 2000 22:37:19 -0800 (PST) (envelope-from nobody@FreeBSD.org) Message-Id: <200002240637.WAA69495@freefall.freebsd.org> Date: Wed, 23 Feb 2000 22:37:19 -0800 (PST) From: spock@techfour.net To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/16954: [PATCH] catopen(3) in libc can overflow on $NLSPATH Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 16954 >Category: misc >Synopsis: [PATCH] catopen(3) in libc can overflow on $NLSPATH >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Feb 23 22:40:01 PST 2000 >Closed-Date: >Last-Modified: >Originator: Mike Heffner >Release: 4.0-current >Organization: >Environment: FreeBSD 4.0-CURRENT #0: Sat Feb 19 20:05:45 EST 2000 >Description: The function catopen(3) in libc can overflow if $NLSPATH is too long. This can be noticed by running /usr/bin/ee. >How-To-Repeat: $ NLSPATH=[5120] ee >Fix: Apply patch and recompile libc Index: lib/libc/nls/msgcat.c =================================================================== RCS file: /home/ncvs/src/lib/libc/nls/msgcat.c,v retrieving revision 1.21 diff -u -r1.21 msgcat.c --- msgcat.c 2000/01/27 23:06:33 1.21 +++ msgcat.c 2000/02/02 19:38:09 @@ -92,8 +92,9 @@ char *nlspath; char *lang; long len; - char *base, *cptr, *pathP; + char *base, *cptr; struct stat sbuf; + int j; if (!name || !*name) { errno = EINVAL; @@ -127,20 +128,22 @@ for (nlspath = cptr; *cptr; ++cptr) { if (*cptr == ':') { *cptr = '\0'; - for (pathP = path; *nlspath; ++nlspath) { + for (j=0; *nlspath; ++nlspath) { if (*nlspath == '%') { if (*(nlspath + 1) == 'L') { ++nlspath; - strcpy(pathP, lang); - pathP += strlen(lang); + strncpy(path+j, lang, sizeof(path)-j-1); + j += strlen(path+j); } else if (*(nlspath + 1) == 'N') { ++nlspath; - strcpy(pathP, name); - pathP += strlen(name); - } else *(pathP++) = *nlspath; - } else *(pathP++) = *nlspath; + strncpy(path+j, name, sizeof(path)-j-1); + j += strlen(path+j); + } else if(sizeof(path)-j-1) + path[j++] = *nlspath; + } else if(sizeof(path)-j-1) + path[j++] = *nlspath; } - *pathP = '\0'; + path[j] = '\0'; if (stat(path, &sbuf) == 0) { catpath = path; break; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message