From nobody@FreeBSD.org  Fri Mar 12 07:24:53 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B1DA916A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Mar 2004 07:24:53 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9085B43D1F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Mar 2004 07:24:53 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i2CFOr72083532
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 12 Mar 2004 07:24:53 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i2CFOrUr083531;
	Fri, 12 Mar 2004 07:24:53 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200403121524.i2CFOrUr083531@www.freebsd.org>
Date: Fri, 12 Mar 2004 07:24:53 -0800 (PST)
From: Claes M Nyberg <md0claes@mdstud.chalmers.se>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Buffer overflow in /usr/bin/indent
X-Send-Pr-Version: www-2.3

>Number:         64164
>Category:       bin
>Synopsis:       Buffer overflow in /usr/bin/indent
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 12 07:30:22 PST 2004
>Closed-Date:    Sun Sep 19 20:35:37 GMT 2004
>Last-Modified:  Sun Sep 19 20:35:37 GMT 2004
>Originator:     Claes M Nyberg
>Release:        5.1-RELEASE
>Organization:
>Environment:
FreeBSD mastercom.powerland.box 5.1-RELEASE FreeBSD 5.1-RELEASE #2: Mon Oct 20 21:06:14 CEST 2003     cmn@mastercom.powerland.box:/usr/src/sys/i386/compile/MASTERCOM  i386
      
>Description:
/usr/bin/indent crashes with a long HOME environmental variable.
Line 171 in args.c: sprintf(fname, "%s/%s", getenv("HOME"), prof);

Other locations that lacks boundary checking (which might, or might not crash the program):

cd /usr/src/usr.bin/indent
$ iseec -v *.c
Parsing 'args.c'
Parsing 'indent.c'
Parsing 'io.c'
Parsing 'lexi.c'
Parsing 'parse.c'
Parsing 'pr_comment.c'
Function "main" found on line 73 in file indent.c
Found 19 global and 5 private functions in 6 files
(iseec) audit efuncs -vvvv
Using sprintf
Using strcpy
Using creat
Using getc
Using getenv
(iseec) audit efuncs
Using sprintf
Using strcpy
(iseec) calls --to sprintf -a
Function 'sprintf' not found in global table
Found function 'sprintf' in external table
[indent.c:501] main -> sprintf
[indent.c:572] main -> sprintf 
[indent.c:914] main -> sprintf 
[args.c:171] set_profile -> sprintf
[indent.c:1154] bakcopy -> sprintf
(iseec) print indent.c -s 501 -l1
    sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
(iseec) print indent.c -s 572 -l1
    sprintf(e_code, "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
(iseec) print indent.c -s 914 -l1
    sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
(iseec) print args.c -s 171 -l1
    sprintf(fname, "%s/%s", getenv("HOME"), prof);
(iseec) print indent.c -s 1154
    sprintf(bakfile, "%s.BAK", p);
(iseec)



>How-To-Repeat:
$ export HOME=`perl -e'{ print "A"x8192; }'`
$ gdb `which indent`
GNU gdb 5.2.1 (FreeBSD)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-undermydesk-freebsd"...
(no debugging symbols found)...
(gdb) r
Starting program: /usr/bin/indent
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb)

>Fix:
Use snprintf(3) instead of sprintf(3).

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Sun Sep 19 20:35:12 GMT 2004 
State-Changed-Why:  
Fixed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=64164 
>Unformatted:
